#include <iostream>
using namespace std ;
int main() {
//Variables
char country;
int taxed ;
float pay ;
char uk_tax = 'a'; //40%
char us_tax ='b';//mulitple by number devide answer by 100
//Inputs
cout << "Enter your total earnings: ";
cin >> pay ;
cout << "Are you within the UK or USA?\n ";
cout << "a) For Uk b) For USA \n ";
cin >> country ;
switch(country)
{
case 1:
//chosen if input is a
if (country == uk_tax)
taxed = 40 * pay/100;
cout<< "Here are your earnings after Tax £" << taxed ;
break;
case 2:
//chosen if input is b
if (country == us_tax)
taxed = 28 * pay/100 ;
cout << "Here are your earning after Tax £" << taxed ;
break;
} return 0 }
你好我只是想知道是否有人可以帮助看到我与这段代码有问题。代码不执行开关语句。代码它自己它只是两个国家(美国,英国)的税计算器用户通过输入'a'或'b'选择国家,但我似乎无法得到它执行switch语句后执行switch语句?
也许是因为'country'不是1或2? – immibis
案件是“a”和“b”不是“1”和“2”。 – NathanOliver
@NathanOliver:实际上是''a''和''b''。 –