Thread: colors (again)

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    colors (again)

    the code
    again = "yes";
    while (again == "y" || again =="yes") {
    cout << "Pick a color (select using number)" << endl ;
    cout << "1. Red text Black background" << endl ;
    cout << "2. Red text Blue background" << endl ;
    cout << "3. Red text Green background" << endl ;
    cout << "4. Red text White background" << endl ;
    cout << "5. Black text White background" << endl ;
    cout << "6. Black text Red background" << endl ;
    cout << "7. Black text Green background" << endl ;
    cout << "8. Black text Blue background" << endl ;
    cout << "9. Blue text Black background" << endl ;
    cout << "10. Blue text Red background" << endl ;
    cout << "11. Blue text Green background" << endl ;
    cout << "12. Blue text White background" << endl ;
    cout << "13. Green text Black background" << endl ;
    cout << "14. Green text Red background" << endl ;
    cout << "15. Green text Blue background" << endl ;
    cout << "16. Green text White background" << endl ;
    cout << "17. White text Black background(defualt)" << endl ;
    cout << "18. White text Red background" << endl ;
    cout << "19. White text Blue background" << endl ;
    cout << "20. White text Green background" << endl ;
    cin >> color;
    if(color == "1")
    goto 1;
    else if(color == "2")
    goto 2;
    else if(color == "3")
    goto 3;
    else if(color == "4")
    goto 4;
    else if(color == "5")
    goto 5;
    else if(color == "6")
    goto 6;
    else if(color == "7")
    goto 7;
    else if(color == "8")
    goto 8;
    else if(color == "9")
    goto 9;
    else if(color == "10")
    goto 10;
    else if(color == "11")
    goto 11;
    else if(color == "12")
    goto 12;
    else if(color == "13")
    goto 13;
    else if(color == "14")
    goto 14;
    else if(color == "15")
    goto 15;
    else if(color == "16")
    goto 16;
    else if(color == "17")
    goto 17;
    else if(color == "18")
    goto 18;
    else if(color == "19")
    goto 19;
    else if(color == "20")
    goto 20;
    1:textcolor(RED);
    textbackground(BLACK);
    clrscr();
    goto endcolor;
    2:textcolor(RED);
    textbackground(BLUE);
    clrscr();
    goto endcolor;
    3:textcolor(RED);
    textbackground(GREEN);
    clrscr();
    goto endcolor;
    4:textcolor(RED);
    textbackground(WHITE);
    clrscr();
    goto endcolor;
    5:textcolor(BLACK);
    textbackground(WHITE);
    clrscr();
    goto endcolor;
    6:textcolor(BLACK);
    textbackground(RED);
    clrscr();
    goto endcolor;
    7:textcolor(BLACK);
    textbackground(GREEN);
    clrscr();
    goto endcolor;
    8:textcolor(BLACK);
    textbackground(BLUE);
    clrscr();
    goto endcolor;
    9:textcolor(BLUE);
    textbackground(BLACK);
    clrscr();
    goto endcolor;
    10:textcolor(BLUE);
    textbackground(RED);
    clrscr();
    goto endcolor;
    11:textcolor(BLUE);
    textbackground(GREEN);
    clrscr();
    goto endcolor;
    12:textcolor(BLUE);
    textbackground(WHITE);
    clrscr();
    goto endcolor;
    13:textcolor(GREEN);
    textbackground(BLACK);
    clrscr();
    goto endcolor;
    14:textcolor(GREEN);
    textbackground(RED);
    clrscr();
    goto endcolor;
    15:textcolor(GREEN);
    textbackground(BLUE);
    clrscr();
    goto endcolor;
    16:textcolor(GREEN);
    textbackground(WHITE);
    clrscr();
    goto endcolor;
    17:textcolor(WHITE);
    textbackground(BLACK);
    clrscr();
    goto endcolor;
    18:textcolor(WHITE);
    textbackground(RED);
    clrscr();
    goto endcolor;
    19:textcolor(WHITE);
    textbackground(BLUE);
    clrscr();
    goto endcolor;
    20:textcolor(WHITE);
    textbackground(GREEN);
    clrscr();
    goto endcolor;
    endcolor: cout << "Would you like to change the colors again? (y/n)" << endl;
    cin >> again;
    if(again == "n" || again == "no")
    goto startofprogram;
    } // <- goes to the while at the beggening of change colors
    the error
    parse error before `:'
    that error si for every line with a name like 1: 2: and 3: and so on. what am i doing wrong, do i ahve to many gotos or something. this is the most common error i get, but this time i dont see how to fix it
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Re: colors (again)

    Originally posted by Klinerr1
    do i ahve to many gotos or something
    Yes you do, but that isn't your error. Anyways why don't you just use a switch statement? So much cleaner to read and people are less likely to flame you

    Anyways, what are all of your data types? In particular what are color and again ?

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    Thumbs up Maybe a shorter menu...

    You should let them choose from a background color, and a text color, instead of having to use up space with all the possible combinations. Like first they choose text color, then background color, then based on that it changes it accordingly. Just a thought...
    "Um...well..."
    -Kyoto Oshiro

  4. #4
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    again is string, color was float, but c++ dint like it now it doesnt mind it being string also. i didnt think fo using switches. ill try that and say if it helped, cuas ei dont like using goto, hear its bad practice, but sometimes i ahve no chioce
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Klinerr1
    again is string, color was float, but c++ dint like it now it doesnt mind it being string also. i didnt think fo using switches. ill try that and say if it helped, cuas ei dont like using goto, hear its bad practice, but sometimes i ahve no chioce
    If color was a int you should compare like NOT like this

    else if(color == "20")

    but instead like this

    else if(color == 20)

    Remeber, there are only rare cases that you cannot avoid using goto's .. just think about it for a while and surely you can develop a new design If you have problems with the switch statement, just ask.

  6. #6
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    Posts
    107
    You shouldn't code all the colors in different places in the code. Put them in an array and go that through once with loop or load the colors from a file.

  7. #7
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    end post.. i figured it all out, i used switches
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why I only get 8 colors out of ncurses?
    By Nazgulled in forum C Programming
    Replies: 3
    Last Post: 05-08-2007, 06:06 PM
  2. Relation between material colors and light colors.
    By indigo0086 in forum Game Programming
    Replies: 3
    Last Post: 04-18-2007, 03:20 PM
  3. colors in forefox and colors in IE
    By MisterSako in forum Tech Board
    Replies: 3
    Last Post: 05-15-2006, 01:59 PM
  4. colors?
    By planet_abhi in forum Game Programming
    Replies: 1
    Last Post: 09-10-2003, 05:37 PM
  5. Text Colors
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 07-11-2002, 06:57 AM