2015-01-07 50 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)