我正在编写一个汽车经销商程序,在该程序中,您要求用户输入他们的选择(1.福特2.Mustang),但是它没有显示最终选择的内容,而是显示了数字选择。而不是显示“您选择了红色2015雪佛兰Malibu”或类似的名称,而是显示了“您选择了1 1 1 1”。这是代码。
UPDATE 我已经切换到用例,但仍然得到相同的输出。
#include <iostream>
using namespace std;
void cars();
int main()
{
int option;
cout << "Hello! Thank you for using CarRight Solutions!\n";
cout << "We have a nice selection of sudans to choose from. Press 1 to start
your search for the right car. \n\n" << endl;
cout << "1. Cars\n";
cin >> option;
if (option == 1)
{
cars();
}
system("pause");
return 0;
}
void cars ()
{
int make, model, year, color;
cout << "\n *****CARS SELECTION***** \n";
cout << "Select a make. \n" << endl;
cout << "1. Chevorlet \n";
cout << "2. Nissan \n";
cout << "3. Honda \n";
cout << "4. Toyota \n";
cin >> make;
switch (make) {
case 1:
cout << "\n You have selected Chevorlet.\n";
cout << "Please select a model. \n";
cout << "1. Malibu \n";
cout << "2. Impala \n";
cin >> model;
switch(model) {
case 1:
cout << "\n You have selected Malibu. \n";
cout << "Please select a year. \n";
cout << "1. 2017 \n";
cout << "2. 2018 \n";
cout << "3. 2019 \n";
cin >> year;
switch(year) {
case 1:
cout << "\n You have selected 2017. \n";
cout << "Select a color. \n\n";
cout << "1. Black \n";
cout << "2. White \n";
cout << "6. Blue \n";
cin >> color;
switch(color) {
case 1:
cout << "\n You have selected Black.\n";
cout << "A" << color << "," << year << "," << make << "," << model
<< " will be around $20,000.";
}
}
}}}
输出仍然是: // A1,1,1,1约为20,000美元。
答案 0 :(得分:0)
您打印“ make”值
cout << "\n You have selected" << make
但是您需要使用像这样的开关运算符
switch(make){
情况1: 打破; 情况2: 打破; }