Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 86,372 C++ Programmers. There are 1,438 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a C++ Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

switchs

 
Reply to this topicStart new topic

switchs, I run DEV C++

Holden117
post 9 May, 2008 - 08:41 AM
Post #1


D.I.C Head

**
Joined: 16 Feb, 2008
Posts: 168



I have a problem. I am trying to start a never ending loop. For some reason it will not work. HELP PLEASE!

CODE
#include <iostream>

using namespace std;
int main()
{
      system("cmd");
      system("color 29");
      
      switch("cmd");
      {
                    case 1 : system("color 01");
                    break;
                    case 2 : system("color 02");
                    break;
                    case 3 : system("color 03");
                    break;
                    case 4 : system("color 04");
                    break;
                    case 5 : system("color 05");
                    break;
                    case 6 : system("color 06");
                    break;
      }
      cin.get();
}


Errors:
C:\Documents and Settings\1337\Desktop\Untitled1.cpp In function `int main()':
9 C:\Documents and Settings\1337\Desktop\Untitled1.cpp switch quantity not an integer
11 C:\Documents and Settings\1337\Desktop\Untitled1.cpp case label `1' not within a switch statement
12 C:\Documents and Settings\1337\Desktop\Untitled1.cpp break statement not within loop or switch
13 C:\Documents and Settings\1337\Desktop\Untitled1.cpp case label `2' not within a switch statement
14 C:\Documents and Settings\1337\Desktop\Untitled1.cpp break statement not within loop or switch
15 C:\Documents and Settings\1337\Desktop\Untitled1.cpp case label `3' not within a switch statement
16 C:\Documents and Settings\1337\Desktop\Untitled1.cpp break statement not within loop or switch
17 C:\Documents and Settings\1337\Desktop\Untitled1.cpp case label `4' not within a switch statement
18 C:\Documents and Settings\1337\Desktop\Untitled1.cpp break statement not within loop or switch
19 C:\Documents and Settings\1337\Desktop\Untitled1.cpp case label `5' not within a switch statement
20 C:\Documents and Settings\1337\Desktop\Untitled1.cpp break statement not within loop or switch
21 C:\Documents and Settings\1337\Desktop\Untitled1.cpp case label `6' not within a switch statement
22 C:\Documents and Settings\1337\Desktop\Untitled1.cpp break statement not within loop or switch

I have a crap load of errors.

The point of the program is to make the command prompt change colors. I have spare time right now if you can't tell.

User is offlineProfile CardPM
Go to the top of the page
+Quote Post


1lacca
post 9 May, 2008 - 08:46 AM
Post #2


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,192

You can only switch on an int, like
CODE

int a;

//put some meaningful value into a

switch(a){
case 1:
//...

Putting a string into the switch won't work.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Holden117
post 9 May, 2008 - 09:02 AM
Post #3


D.I.C Head

**
Joined: 16 Feb, 2008
Posts: 168

Crap I did that but the switch is not doing anything to the command promt. It just stays black and white.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

cboyd7539
post 9 May, 2008 - 09:23 AM
Post #4


New D.I.C Head

*
Joined: 4 Feb, 2008
Posts: 9

CODE
switch("cmd");


Maybe you should remove the semicolon from here, since the semicolon ends the statement.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Holden117
post 9 May, 2008 - 09:37 AM
Post #5


D.I.C Head

**
Joined: 16 Feb, 2008
Posts: 168

QUOTE(cboyd7539 @ 9 May, 2008 - 09:23 AM) *

CODE
switch("cmd");


Maybe you should remove the semicolon from here, since the semicolon ends the statement.

Thanks though. I did do that.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

gabehabe
post 9 May, 2008 - 11:31 AM
Post #6


D.I.C Regular

***
Joined: 6 Feb, 2008
Posts: 390

I'm not sure if your problem has been solved now, but I just edited your code and added comments for you to see what happens where:
cpp
#include <iostream>

using namespace std;
int main()
{
//system("cmd");
// you dont need the line above, it doesn't do anything
system("color 29"); // sets an initial colour state

int choice; // the number that the user will enter

cout << "Enter a number between 1 and 6: "; // prompt
cin >> choice; // get the choice

switch(choice) // switch to the corresponding case for choice
{
case 1 : system("color 01");
break;
case 2 : system("color 02");
break;
case 3 : system("color 03");
break;
case 4 : system("color 04");
break;
case 5 : system("color 05");
break;
case 6 : system("color 06");
break;
// think about adding a default for errors
default: cout << "Invalid choice" << endl;
}
system("pause"); // Press any key to continue . . .
return EXIT_SUCCESS; // everything went OK
}

Hope this helps smile.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Holden117
post 12 May, 2008 - 08:13 AM
Post #7


D.I.C Head

**
Joined: 16 Feb, 2008
Posts: 168

I fix it a different way and now I just need the color to change while the numbers are adding. Code:
CODE
#include <iostream>

using namespace std;                    
                    
// adder  what the hell is wrong
int main()
{
int number, color;
int max;
cout << "enter your number" << endl;
cin >> number;
cout << "enter your max number" << endl;
cin >> max;

for (number = 1; number <= max; number++)
cout << number;
for (color = 1; color <= max; color++)              
switch(color)        

      {            
                    case 1 :
                         system("color 01");
                    break;
                    case 2 :
                         system("color 02");
                    break;
                    case 3 :
                         system("color 03");
                    break;
                    case 4 :
                         system("color 04");
                    break;
                    case 5 :
                         system("color 05");
                    break;
                    case 6 :
                         system("color 06");
                    break;
                    case 7 :
                         system("color 07");
                    break;
                    case 8 :
                         system("color 10");
                    break;
                    case 9 :
                         system("color 12");
                    break;
                    case 10 :
                         system("color 13");
                    break;
                    case 11 :
                         system("color 14");
                    break;
                    case 12 :
                         system("color 15");
                    break;
                    case 13 :
                         system("color 16");
                    break;
                    case 14 :
                         system("color 17");
                    break;        
                    case 15 :
                         system("color 20");
                    break;
                    case 16 :
                         system("color 21");
                    break;
                    case 17 :
                         system("color 22");
                    break;
                    case 18 :
                         system("color 23");
                    break;
                    case 19 :
                         system("color 24");
                    break;          
                    case 20 :
                         system("color 25");
                    break;
                    case 21 :
                         system("color 26");
                    break;
                    case 22 :
                         system("color 27");
                    break;
                    case 23 :
                         system("color 30");
                    break;
                    case 24 :
                         system("color 31");
                    break;
                    case 25 :
                         system("color 32");
                    break;
                    case 26 :
                         system("color 33");
                    break;
                    case 27 :
                         system("color 34");
                    break;
                    case 28 :
                         system("color 35");
                    break;
                    case 29 :
                         system("color 36");
                    break;
                    case 30 :
                         system("color 37");
                    break;
                    case 31 :
                         system("color 40");
                    break;
                    case 32 :
                         system("color 41");
                    break;
                    case 33 :
                         system("color 42");
                    break;
                    case 34 :
                         system("color 43");
                    break;
                    case 35 :
                         system("color 44");
                    break;
                    case 36 :
                         system("color 45");
                    break;
                    case 37 :
                         system("color 46");
                    break;
                    case 38 :
                         system("color 47");
                    break;
                    case 39 :
                         system("color 50");
                    break;
                    case 40 :
                         system("color 51");
                    break;
                    case 41 :
                         system("color 52");
                    break;  
                    case 42 :
                         system("color 53");
                    break;
                    case 43 :
                         system("color 54");
                    break;
                    case 44 :
                         system("color 55");
                    break;
                    case 45 :
                         system("color 56");
                    break;  
                    case 46 :
                         system("color 57");
                    break;
                    case 47 :
                         system("color 60");
                    break;
                    case 48 :
                         system("color 61");
                    break;
                    case 49 :
                         system("color 62");
                    break;
                    case 50 :
                         system("color 63");
                    break;
                    case 51 :
                         system("color 64");
                    break;
                    case 52 :
                         system("color 65");
                    break;  
                    case 53 :
                         system("color 66");
                    break;  
                    case 54 :
                         system("color 67");
                    break;
                    case 55 :
                         system("color 70");
                    break;  
                    case 56 :
                         system("color 71");
                    break;  
                    case 57 :
                         system("color 72");
                    break;
                    case 58 :
                         system("color 73");
                    break;  
                    case 59 :
                         system("color 74");
                    break;
                    case 60 :
                         system("color 75");
                    break;              
                    case 61 :
                         system("color 76");
                    break;
                    default :
                         system("color 77");
                         color = 0;
                    break;                                                                                                                                                                              
      }
      cin.get();
}

User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
Time is now: 5/17/08 02:41AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month