Help?

closed account (iNU7ko23)
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
cout << "Hi! Do you want to take a quest to kill the evil dragon!";
cout << "(Reply 1 for yes)";
char reply;
cin >> reply;
switch(reply) {
case "1":
cout << "Great let's start the quest!";
break;
default:
cout << "Thanks alot!";
break;
}
return 0;
}




How come when I type this in and run it. Whatever I press it says "Thanks alot!"
You need to change it from `case "1":` to `case '1':` double quotes are string literals and single quotes are for characters.
your error is line 6:
case "1"; // no!

case '1'; // yes!

"1" gives you a string literal, or a pointer to a constant null-terminated string.
closed account (zb0S216C)
The case label must evaluate to an integral constant.

Just so you know, case "1": is equivalent to case "1"[0]:

Wazzak
Last edited on
@Framework: you mean integral; I am pretty sure that 1ULL does not cast silently to an int but that it can be used in switch statements when switching on an unsigned long long ;)
closed account (zb0S216C)
Keep your alans on, Gates, I'll change it :)P

Wazzak
Topic archived. No new replies allowed.