#include <iostream>
using namespace std;
#include <cstring>
#include <cstdlib>
int main () {
std::string name;
cout<<"your name? \n\n";
getline (cin,name);
char answer;
cout<<""<<name<<" what is 5*2 ";
cin>>answer;
switch (answer) {
case '1':
std::cout << "GOOD JOB!! ";
break;
default:
cout<<""<<name<<" what is 5*2 ";
cin>>answer;
switch (answer) {
case '1':
std::cout << "GOOD JOB!! \n";
break;
case 'N':
case 'n':
std::cout << "sorry, that is not the answer. \n";
break;
default:
cout<<"you only get 2 shots \n";
break;
}
break;
}
Also, I think it should be <string> not cstring in your header.
Unfortunately your switch statement makes no sense.
If you want a switch then make the 'answer' an int not a char.
If you want to repeat the switch then put it in a do-while loop as shown.
If you want a switch then make the 'answer' an int not a char.
Actually if it is a single char, switch construct does support it. Of cuz normally we use int but I have seen other ppl code where they use a single char.
I think that was the problem though, 2 characters were needed for his char. And since it was 2*5 the simplest solution is to make it an int so user can input 10 or 2032 etc. I guess I should have been clear that this was for his example only and not a universal c++ rule.