About C++ programming?

2016-10-07 3:20 am
cout << "Please choose one of the below: " << endl;
cout << "( Type in a / b / c / d )" << endl;
cout << endl;
cout << "a. 123" << endl;
cout << "b. 456" << endl;
cout << "c. 789" << endl;
cout << "d. 012" << endl;

string answer;
string a, b, c, d;

cin >> answer;

if (answer == a)
{
cout << "you are correct" << endl;
}
else if (happiness == b)
{
cout << "you are wrong" << endl;
}
else if (happiness == c)
{
cout << "you are correct" << endl;
}
else if (happiness == d)
{
cout << "you are correct" << endl;
}

------------

I want to make an MCQ
But I can't output this
Please tell me where is wrong
Thank you so much!!
更新1:

*happiness = answer (wrong typing)

回答 (1)

2016-10-07 4:50 am
Everything is wrong but I cannot tell you anything until you describe what your program is trying to do.
OK, now I see what you wanted. But, Instead of teaching you, I will just give it to you directly.

// program starts here
#include<iostream>
using namespace std;
int main(void){
cout << "Please select one of the below: " << endl;
cout << "( Type in a / b / c / d )" << endl;
cout << endl;
cout << "a. 123" << endl;
cout << "b. 456" << endl;
cout << "c. 789" << endl;
cout << "d. 012" << endl;

char answer;
cin >> answer;
switch(answer){
default: cout << "you are correct" << endl; break;
case 'b': cout << "you are super wrong" << endl; break;
}
return 0;
}


收錄日期: 2021-04-23 22:02:44
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20161006192057AAct5Xz

檢視 Wayback Machine 備份