无论用户选择是否键入小写字母,这都会输出大写字母“ S”或“ P”。当我用代码中的其他语句进行提示时,输出将起作用,但是...我想在最终的cout语句中显示STANDARD或PREMIUM。
如何更改char的值以输出STANDARD或PREMIUM?
#include <string>
#include <iostream>
char meal;
cout << endl << "Meal type: standard or premium (S/P)? ";
cin >> meal;
meal = toupper(meal);
if (meal == 'S'){
meal = 'S';
}
else{
meal = 'P';
}
我尝试过进餐=“标准”,进餐=“高级”,它不起作用。
#include<iostream>
#include<string>
using namespace std;
int main(int argc, char* argv)
{
char meal = '\0';
cout << "Meal type: standard or premium (s/p)?" << endl;;
string mealLevel = "";
cin >> meal;
meal = toupper(meal);
if (meal == 'S'){
mealLevel = "Standard";
}
else{
mealLevel = "Premium";
}
cout << mealLevel << endl;
return 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句