Hi there,
I'm learning C++ and I've only recently started, and learning by online tutorials, videos etc. I'm currently trying to learn how to use a Switch case.
I've got a simple question of "what is your favourite colour?".
Answers being 1) Red, 2) Blue etc. The first 4 cases work. I am now trying to get the final 5) Other to work. I want to be able to ask the user for the "Other" colour they prefer, and then for it then to come up with "your favourite colour is 'Whatever the input was'".
I've got the same code what's used for the rest of my cases.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
switch (A){
case 1:
cout << "Your favourite colour is Red!" << endl;
break ;
case 2:
cout << "Your favourite colour is Blue!";
break ;
case 3:
cout << "Your favourite colour is Green!";
break ;
case 4: cout << "Your favourite colour is Yellow!";
break;
case 5:
cout << "Another colour? Which colour is your favourite?";
cin >> B;
cout << " Your favourite colour is " << B << endl;
break;
}
}
|
But for some reason, I probably am making a stupid mistake here, but the response I get from the console application when the 5th case is used, is..
Another colour? Which colour is your favourite? Your favourite colour is 0.
Press any key to continue.
Am I not able to gain input twice, or am I using wrong data types?
Like I said I'm a beginner so any advice/help would be useful.
Thanks in advance.
Brad.