我怎样才能循环我的程序

时间:2015-01-07 11:22:41

标签: c++ visual-c++

我对c ++编程很陌生,而且我已经制作了一个有效的税收计算器。但我不想循环,而不是在完成时关闭。这是怎么做到的?

// ConsoleApplication5.cpp:定义控制台应用程序的入口点。

代码

#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;
}

1 个答案:

答案 0 :(得分: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)