Thread: parse error on my program

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    43

    parse error on my program

    Code:
    #include<iostream>
    #include<ctime>
    using namespace std;
    int main()
    {
    cout<<"Welcome To Charlies Slot machine"<<endl;
    cout<<"press 1 to play 2 not to play"<<endl;
    int a;
    cin>>a;
    if (a==1)
    {
    cout<<"You have chosen to play"<<endl;
    cout<<"1 to roll 2 not to roll"<<endl;
    int b;
    cin>>b;
    if (b==1)
    {
    int c;
    srand(time(0));
    c=1+rand()%6;
    cout<<"you rolled"<<c<<" ";
    int d;
    srand(time(0));
    d=1+rand()%6;
    cout<<d<<" ";
    int e;
    srand(time(0));
    e=1+rand()%6;
    cout<<e<<endl;
    if (c==d==e)
    {
    cout<<"you won";
    }
    return 0;
    }
    That is a simple slot machine i made if you get 3 numbers the same you win it sais parse error at the end why is this?
    Last edited by makveli; 11-12-2003 at 10:21 AM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You're missing a few closing braces...
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    43
    can someone put them in ive been pulling my hair out tryin to figure out where they go to no avail

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    that's doing your work for you, but okay:
    Code:
    #include<iostream>
    #include <cstdlib>
    #include<ctime>
    
    using namespace std;
    
    int main()
    {
       cout<<"Welcome To Charlies Slot machine"<<endl;
       cout<<"press 1 to play 2 not to play"<<endl;
    
       int a;
       cin>>a;
    
       if (a==1)
       {
          cout<<"You have chosen to play"<<endl;
          cout<<"1 to roll 2 not to roll"<<endl;
    
          int b;
          cin>>b;
    
          if (b==1)
         {
             int c;
             srand(time(0));
             c=1+rand()%6;
             cout<<"you rolled"<<c<<" ";
             int d;
             srand(time(0));
             d=1+rand()%6;
             cout<<d<<" ";
             int e;
             srand(time(0));
             e=1+rand()%6;
             cout<<e<<endl;
             if (c==d && d==e && c==e)
                   {
                       cout<<"you won";
                   }
          }   //second if
       }   //first if
       return 0;
    }
    that's why you should space your code correctly

    your code is a mess anyway, so i'm going to rewrite it for you:
    Code:
    #include<iostream>
    #include<ctime>
    #include <cstdlib>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main()
    {
       int option,roll,nextroll;
       bool win=true;
       srand(clock());
    
       cout<<"Welcome To Charlies Slot machine"<<endl;
       cout<<"press 1 to play 2 not to play"<<endl;
    
       cin>>option;
    
       if (a==1)
       {
          cout<<"You have chosen to play"<<endl;
          cout<<"1 to roll 2 not to roll"<<endl;
    
          cin>>option;
    
          if (option==1)
         {
             roll=1+rand()%6;
             cout<<"you rolled"<<roll<<" ";
    
             nextroll=1+rand()%6;
    
             if(nextroll!=roll)
                win=false;
    
             roll=nextroll;
             cout<<roll<<" ";
    
             nextroll=1+rand()%6;
    
             if(nextroll!=roll)
                win=false;
    
             roll=nextroll;
             cout<<roll<<endl;
    
             if (win)
                       cout<<"you won";
          }
       }
    
       cout<<endl<<"Press any key to continue . . . ";
       cin.get();
       return 0;
    }
    even though that progam doesn't make much sense, because you would have to roll the dice the same number 3 times...
    Last edited by major_small; 11-12-2003 at 11:05 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > can someone put them in ive been pulling my hair out tryin to figure out where they go to no avail
    If you type the closing &#125; ) ] " ' or whatever, and make sure the code is correctly indented before filling in the body, then the issue of missing closing whatever never arises.

    Sure it's a few extra cursor movements, but it sure saves some headaches later on.

    As does pressing the compile button every time you add a new brace pair (say a loop or a function stub or whatever).

    If you're especially lazy, you can get an auto-completing text editor which can insert this stuff for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    43
    yeh i just got a bit coinfused i know what to do now and thanx for the && idea on how to make variables equal each other

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM