c++ - 执行 switch 语句?

标签 c++ switch-statement

<分区>

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

你好,我只是想知道是否有人可以帮忙看看我在使用这段代码时遇到的问题。该代码不执行 switch 语句。代码本身只是两个国家(美国、英国)的税收计算器,用户通过输入“a”或“b”来选择国家,但我似乎无法获得它在

之后执行 switch 语句

最佳答案

如果您的变量 country 不是 1 或 2,那么 switch 将不会执行任何操作。 另外,如果您的案例是:

可能会更好

案例“a”:

case 'b':

关于c++ - 执行 switch 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34075970/

相关文章:

java - java 中的可调/变量开关案例

c++ - 如何使用 COM 智能指针作为调用的输入输出参数库函数

c++ - 对函数的重新定义和模糊调用具有数组参数

c++ - CPlex 和 C++ 错误 : no matching function for call to ‘IloModel::add(bool)’

javascript - 如何将代码从多个 if 语句更改为 Switch Case 语句

objective-c - 开关条件有 boolean 值?

c# - linq中的switch case

c++ - 使用默认值初始化成员引用

c++ - 在 CLion 中使用 GLib

enums - 在 Swift 中使用 switch 枚举