ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#include <iostream.h>
int main ()
{
char sh;
cout << "enter the name of today ( -1 to end )";
cin >> sh;
while ( sh != EOF ) {
switch ( sh )
{
case 1 'sat' ; cout << " huh go to school "; break;
case 2 'sun' ; cout << " huh go to school "; break;
case 3 'mon' ; cout << " huh go to school "; break;
case 4 'tue' ; cout << " huh go to school "; break;
case 5 'wed' ; cout << " huh go to school "; break;
case 6 'Thu' ; cout << " have nice weekend "; break;
case 7 'fri' ; cout << "have nice weekend"; break;
default
cout << "wrong name ";
}
}
cout << " good luck ";
return 0;
}
when i compile it .. the compiler show the following problems
Code:
switch.cpp:10:12: warning: multi-character character constant
switch.cpp: In function `int main()':
switch.cpp:10: error: syntax error before '\x736174'
switch.cpp:11:12: warning: multi-character character constant
switch.cpp:11: error: syntax error before '\x73756e'
switch.cpp:12:12: warning: multi-character character constant
switch.cpp:12: error: syntax error before '\x6d6f6e'
switch.cpp:13:12: warning: multi-character character constant
switch.cpp:13: error: syntax error before '\x747565'
switch.cpp:14:12: warning: multi-character character constant
switch.cpp:14: error: syntax error before '\x776564'
switch.cpp:15:12: warning: multi-character character constant
switch.cpp:15: error: syntax error before '\x546875'
switch.cpp:16:12: warning: multi-character character constant
switch.cpp:16: error: syntax error before '\x667269'
switch.cpp:18: error: syntax error before `<<' token
switch.cpp:10: warning: unreachable code at beginning of switch statement
You're not going to be able to use switch() on a day name. You could rewrite it expecting the user to type a day number though (e.g. Sunday = 0, Monday = 1, etc.)
You might want to review how to write case conditions, because yours aren't quite right. Each case condition has to be an integer. Also, 'mon' isn't even valid code. "mon" would be valid, but you can't test against "mon" with switch/case. Well, you could, but no one in their right mind would. It wouldn't work the way you'd expect.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.