Need Help

This is a discussion on Need Help within the C++ Programming forums, part of the General Programming Boards category; now it sais that case 'S': is not included in the switch statement......

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    55
    now it sais that case 'S': is not included in the switch statement...
    D4050
    Glorified C++ Programmer
    Console, DOS, HTML, Javascript, Visual Basics Compatible

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    55
    nevermind..its working now. just that its always doing defualt..never the cases...
    D4050
    Glorified C++ Programmer
    Console, DOS, HTML, Javascript, Visual Basics Compatible

  3. #18
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    why don't you make sure that all the cases look like this

    switch(entry):
    {

    case 'A':
    case 'a':
    {
    cout << "blah";
    break;
    }

    that way you're sure its not your caps lock or anything....then lemme know how it is....

    *you have been e-mail that i replied because i set it up so that you would be....
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    55
    heh yea i know.that wuz funky "You got a new thread reply" heh. Yea i got it workin a few hours ago...now im having big problems with looping it so theres an option to restart the program. I just DONT get how to do it...some other dude explained it ..kind of...but i didnt understand it...do you think you could help me?

  5. #20
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    check out your other thread...it links to the tutorials on the main site, they're good...if you still have problems PM me or put it up here...I'mm be on for a bout another 15 min or so and maybe some tonight..
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  6. #21
    Registered User
    Join Date
    Oct 2001
    Posts
    55
    k i took a look...this stuff is confusin..im only 12...2 much for my little brain heh as i posted on the other thread...do u think u could go through each block of code to make me understand it? id really appreciate it
    D4050
    Glorified C++ Programmer
    Console, DOS, HTML, Javascript, Visual Basics Compatible

  7. #22
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    yup....here we go....don't have time to do all three kinds of loops so I'm just gonna do a for loop for now....I'll show you whiles and do whiles later.....

    int i=0;

    for(i=0;i<10;i++)
    /*this starts the loop, there are 3 sections here the first one "(i=0)" sets your variable, here it's redundunt because i did it above but oh well (you could also do int i=0 here); section 2: "i<10;" this is the statement that says how long you want the loop to run for, in this case i want it to run "while i is less than 10" you can also do <= (less than or equal to), ==, >, or >=.; the 3rd section "i++), this says that at the END of every run of the loop you want i to equal what it was is at the end plus one. Because this is at the end of the loop that it is added that means that in this case my loop will actually run 10 times once while i==0, i==1, i==2...and at i==9. It checks the while statement at the begining of each run. */
    {

    cout << "I've run " << i << " times" << endl;
    }

    and that's a real simple for loop.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  8. #23
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595

    do while loop

    However what you really want for this is probably a do while loop....

    What it does is it automatically runs atleast 1 time no matter what (because of the do) and then till a paramater is met.

    so for example:

    int k=0;

    do
    {

    cout << "hi bob" << endl;
    k++; //have to put this in here cause its not built in like on the for
    }
    while(k<10); //this one also checks to make sure you're in paramaters at the end instead or the begining.

    Try using that for your program...I'm afk for a while now but if you need help still drop me a line and I'll reply later
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  9. #24
    Registered User
    Join Date
    Oct 2001
    Posts
    55
    Originally posted by kermi3
    yup....here we go....don't have time to do all three kinds of loops so I'm just gonna do a for loop for now....I'll show you whiles and do whiles later.....

    int i=0;

    for(i=0;i<10;i++)
    /*this starts the loop, there are 3 sections here the first one "(i=0)" sets your variable, here it's redundunt because i did it above but oh well (you could also do int i=0 here); section 2: "i<10;" this is the statement that says how long you want the loop to run for, in this case i want it to run "while i is less than 10" you can also do <= (less than or equal to), ==, >, or >=.; the 3rd section "i++), this says that at the END of every run of the loop you want i to equal what it was is at the end plus one. Because this is at the end of the loop that it is added that means that in this case my loop will actually run 10 times once while i==0, i==1, i==2...and at i==9. It checks the while statement at the begining of each run. */
    {

    cout << "I've run " << i << " times" << endl;
    }

    and that's a real simple for loop.


    hmm ok i think im gettin a grasp of it. The main focus of the loop is so at the end of the program theres an option restart the program without closing it...and then if thats wut the user would want to do..it would clear the screen and then start the program all over again. so i get basicly how that loop would work...but how would i put together the loop im looking for? heres the code for my program...


    /* DAVES FIRST PROGRAM */
    ///////// david4050@hotmail.com ///////////////


    #include <iostream.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <conio.h>
    int main()
    {

    int x;
    int y;
    int z;
    char entry;
    char entry1;
    char GoOn;
    char Begin;

    cout <<"////////////// EZY Math Calculator ///////////////"<<endl;
    cout <<" david4050@hotmail.com\n\n";
    cout <<"Hey! Welcome to EZY Math Calculator."<< endl;
    cout <<"Enter a number and press Enter.."<< endl;

    cin >> x;

    cout <<"The number you just entered was, " << x << endl;

    cout <<"Please Enter another number and press Enter..."<< endl;

    cin >> y;

    cout <<"Do you want the Program do devide your numbers, multiply, add or subtract?\n\n";
    cout <<" Press M and Enter for multiply\n\n";
    cout <<" Press D and Enter for Divide\n\n";
    cout <<" Press S and Enter for Subtraction\n\n";
    cout <<" Press A and Enter for Addition\n\n";
    cin >> entry;

    switch(entry)
    {
    case 'm':
    case 'M':
    z = x*y;
    cout<<""<<x;
    cout<<" multiplied by "<<y;
    cout<<",equals "<<z <<endl;
    system("PAUSE");

    break;

    case 'D':
    case 'd':
    z = x/y;
    cout<<" "<<x;
    cout<<" divided by "<<y;
    cout<<",equals "<<z <<endl;
    system("PAUSE");
    break;

    case 'S':
    case 's':
    z = x-y;
    cout<<" "<<x;
    cout<<" subtracted by "<<y;
    cout<<",equals "<<z <<endl;
    system("PAUSE");
    break;

    case 'A':
    case 'a':
    z = x+y;
    cout<<" "<<x;
    cout<<" added by "<<y;
    cout<<",equals "<<z <<endl;
    cout<<"Press Q to Exit otherwise Enter to continue.."<<endl;
    cin>>entry1;
    if (entry1 = ' ')
    {
    Begin;
    }
    else
    {
    system("PAUSE");
    }

    break;

    default:
    {
    cout<<"Sorry, You've entered an invalid character. Please retry!"<<endl;
    }

    }


    return 0;


    }
    D4050
    Glorified C++ Programmer
    Console, DOS, HTML, Javascript, Visual Basics Compatible

  10. #25
    Registered User
    Join Date
    Oct 2001
    Posts
    55
    dont mind the stuff about:

    if (entry1 = ' ')
    {
    Begin;
    }
    else
    {
    system("PAUSE");
    }



    i wuz trying to play around with wierdo loops earlier
    D4050
    Glorified C++ Programmer
    Console, DOS, HTML, Javascript, Visual Basics Compatible

  11. #26
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    ok try this....didn't want to give it all to you but...here's a big hint hehe....

    int stop=0;
    do
    {

    /*your program here*/
    switch(entry)
    {
    case 'Q':
    case 'q':
    {
    stop=1;
    break;
    }
    }

    }
    while(stop==0)


    2 questions for you about the prgram...

    What's the system("PAUSE") for?

    and Are you using /n to go to the next line in your cout's? If so this works but you're better off using endl instead.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  12. #27
    Registered User
    Join Date
    Oct 2001
    Posts
    55
    K i attached the exe version so u can see wut it looks like. the /ns i think i forgot to take out from yesterday when i thought they were vital to the program.....hey...i didnt know wut cout meant yesterday lol...and as for the system("PAUSE") ...so the program duznt close on me .......hmm..ill try that looping stuff and post a reply shortly
    Attached Files Attached Files
    D4050
    Glorified C++ Programmer
    Console, DOS, HTML, Javascript, Visual Basics Compatible

  13. #28
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    looks good...though you might want to put a getch(); at the end of it...now get that loop setup and you'll be all set.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  14. #29
    Registered User
    Join Date
    Oct 2001
    Posts
    55
    K done...thanks for ur help on this i got a good grasp of it now..the only two problems are..now in the second thing after it loops it....if i accidentilly enter a letter instead of a number when it asks for it......BIG mess.....but its hillarious if u look at it...and wut do i put to clear the screen? i looked at the FAQ and did the clrscr() thing but it comes up as this linking error thing. i have #include <conio.h> in there aswell..i dont know wuts wrong
    D4050
    Glorified C++ Programmer
    Console, DOS, HTML, Javascript, Visual Basics Compatible

  15. #30
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    ok first of all include this:

    #include <STDLIB.H>

    that should take care of clrscr();

    second of all are you using a char or an int for your input?

    and finally make sure you have a getch() at the endof your program...if you do I don't think you'll need those syster("PAUSE")'s.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21