gpt4 book ai didi

c++ - Switch 语句未按预期执行

转载 作者:行者123 更新时间:2023-11-30 04:54:30 25 4
gpt4 key购买 nike

<分区>

输入正确的总金额。任何帮助将不胜感激,谢谢。

    #include <iostream>

using namespace std;

int main()
{
float cost2 = 0;
char ch;

cout << "1. Water \t\tRs.10" << endl;
cout << "2. Cola \t\tRs.20" << endl;
cout << "3. Lemonade \t\tRs.15" << endl;
cout << "Enter your choice: " << endl;

cin >> ch;
switch(ch) {
case 1: {
cost2 += 10; // trying to add 10 if input (ch) is 1
break;
}
case 2: {
cost2 += 20;
break;
}
case 3: {
cost2 += 15;
break;
}
}
cout << "The total before tax is: Rs." << cost2 << endl;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com