2015-01-07 78 views
-2

我對C++編程非常新穎,而且我製作了一個運行正常的稅計算器。但我不想循環,完成後不關閉。這是如何完成的?我如何循環我的程序

// ConsoleApplication5.cpp:定義控制檯應用程序的入口點。

CODE

#include "stdafx.h" 
#include "iostream" 
int _tmain(int argc, _TCHAR* argv[]) 
{ 
cout << "Tax calculator" << endl; 
cout << "The availible countries are: [S]weden, [N]orway, \n[F]inland, [R]ussia, [J]apan and [C]hina" << endl; 
char country; 
int amount; 
cout << "Enter Country:" << endl; 
cin >> country; 
cout << "Enter Amount:" << endl; 
cin >> amount; 
if (country == 'S' || country == 's') 
{ 
    const double swetax = 25; 
    double total = 0; 
    total += amount * swetax/100.0; 
    double totalstax = total + amount; 
    cout << "The amount is" << totalstax << " SEK" << endl; 
} 
else if (country == 'N' || country == 'n') 
{ 
    const double ntax = 25; 
    double ntotal = 0; 
    ntotal += amount * ntax/100.0; 
    double totalntax = amount + ntotal; 
    cout << "The amount is" << totalntax << " NOK" << endl; 
    cout << "Want to add tax to another value? (y/n)" << endl; 
} 
else if (country == 'F' || country == 'f') 
{ 
    const double ftax = 24; 
    double ftotal = 0; 
    ftotal += amount * ftax/100.0; 
    double totalftax = amount + ftotal; 
    cout << "The amount is" << totalftax << " EUR" << endl; 
    cout << "Want to add tax to another value? (y/n)" << endl; 
} 
else if (country == 'R' || country == 'r') 
{ 
    const double rtax = 18; 
    double rtotal = 0; 
    rtotal += amount * rtax/100.0; 
    double totalrtax = amount + rtotal; 
    cout << "The amount is" << totalrtax << " RUB" << endl; 
    cout << "Want to add tax to another value? (y/n)" << endl; 
} 
else if (country == 'J' || country == 'j') 
{ 
    const double jtax = 8; 
    double jtotal = 0; 
    jtotal += amount * jtax/100.0; 
    double totaljtax = amount + jtotal; 
    cout << "The amount is" << totaljtax << " JPY" << endl; 
    cout << "Want to add tax to another value? (y/n)" << endl; 
} 
else if (country == 'C' || country == 'c') 
{ 
    const double ctax = 17; 
    double ctotal = 0; 
    ctotal += amount * ctax/100.0; 
    double totalctax = amount + ctotal; 
    cout << "The amount is" << totalctax << " CNY" << endl; 
    cout << "Want to add tax to another value? (y/n)" << endl; 
} 
return 0; 
} 
+0

你是什麼意思循環? – saikumarm

+0

是否要運行相同的程序繼續? –

+0

將你的代碼放在一個循環中{do {..} while while(running);'並根據某些退出條件將運行設置爲true或false。 –

回答

1

也許你可以像下面的一個。

do{//While loop to loop back once done. You can also use while(1) instead do-while 
    cout << "The availible countries are: [S]weden, [N]orway, \n[F]inland, [R]ussia, [J]apan and [C]hina;" << endl; 
    cout<<" Z to break! \n";//Loop will break if user enter Z or z. 
    .....//Your Code goes here 
    else if (country == 'Z' || country == 'z') 
     break; 
}while(1)