Need a little help

This is a discussion on Need a little help within the C++ Programming forums, part of the General Programming Boards category; I am having major trouble with this program. I have over 30 errors and can't figure out what it is. ...

  1. #1
    Unregistered
    Guest

    Angry Need a little help

    I am having major trouble with this program. I have over 30 errors and can't figure out what it is. I know that they are probably related and that they are probable easy. The only problem is that I am tired and cannot think right now. So have fun!! BTW, I am sorry but I know that the indention will be messed up but I don't know how to fix it.

    code:
    #include <iostream.h>
    #include <time.h>
    #include <stdlib.h>

    void pullwheel();
    void disptable();


    int main()
    {
    new int money;
    int play;
    int choice;
    cout<<"Welcome to the Virtual Slot Machine.\n"
    <<"You will start with 100 dollars and the\n"
    <<"amount you input every time is five dollars.\n\n";
    while(play)
    {
    cout<<"Please select one of the following.\n"
    <<"1. Let's Play!\n"
    <<"2. How much dough do I got?\n"
    <<"3. Display values for spun items.\n"
    <<"4. Quit\n";
    cin>>choice;
    switch(choice)
    {
    case 1: pullwheel();
    case 2: cout<<money;
    case 3: cout<<disptable();
    case 4: play=0;
    default: cout<<"Are you a moron? Choose a number 1-4.";
    }
    }
    cout<<"You finished with $"<<money<<".\n\n";
    system{"PAUSE");
    delete money;
    return 0;
    }

    void pullwheel()
    {
    int winnings;
    int item1;
    int item2;
    int item3;
    money=(money-5);
    item1=srand(time(NULL))%5;
    item2=srand(time(NULL))%5;
    item3=srand(time(NULL))%5;
    cout<<"You spun:\n";
    switch(item1)
    {
    case 0:cout<<"@ ";
    case 1:cout<<"# ";
    case 2:cout<<"* ";
    case 3:cout<<"& ";
    case 4:cout<<"^ ";
    }
    switch(item2)
    {
    case 0:cout<<"@ ";
    case 1:cout<<"# ";
    case 2:cout<<"* ";
    case 3:cout<<"& ";
    case 4:cout<<"^ ";
    }
    switch(item3)
    {
    case 0:cout<<"@";
    case 1:cout<<"#";
    case 2:cout<<"*";
    case 3:cout<<"&";
    case 4:cout<<"^";
    }
    if (item1==item2&&item2==item3&&item1==0)
    {winnings=5;}

    if (item1==item2&&item2==item3&&item1==1)
    {winnings=6;}

    if (item1==item2&&item2==item3&&item1==2)
    {winnings=8;}

    if (item1==item2&&item2==item3&&item1==3)
    {winnings=10;}

    if (item1==item2&&item2==item3&&item1==4)
    {winnings=12;}

    money=(money+winnings);

    cout<<"\n\nYou just won "<<winnings<<" dollars.\n"
    <<"You now have "<<money<<" dollars.\n\n";
    }

    void disptable()
    {cout<<"3 @'s returns $5, net gain=$0.\n"
    <<"3 #'s returns $6, net gain=$1.\n"
    <<"3 *'s returns $8, net gain=$3.\n"
    <<"3 &'s returns $10, net gain=$5.\n"
    <<"3 ^'s returns $12, net gain=$7.\n";
    }

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    new int money;

    this is bollacks. you cant use new like that.

    while(play)
    case 2: cout<<money;

    2 examples of use of uninitialised variables.

    delete money;

    money isn't a pointer to a chunk of dynamic memory so you cannot use delete on it.

    void pullwheel()
    {
    int winnings;
    int item1;
    int item2;
    int item3;
    money=(money-5);

    use of variable called money that doesn't even exist

    item1=srand(time(NULL))%5;
    item2=srand(time(NULL))%5;
    item3=srand(time(NULL))%5;

    use of srand() when you should have used rand()

    just a few errors!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Unregistered
    Guest
    I think I fixed all of it. Still not functioning right but doesn't compiler isn't cating it.

    #include <iostream.h>
    #include <time.h>
    #include <stdlib.h>

    int pullwheel();
    int disptable();

    int money=1000;

    int main()
    {
    int play=1;
    int choice;
    cout<<"Welcome to Neil's Virtual Slot Machine.\n"
    <<"You will start with 100 dollars and the\n"
    <<"amount you input is five dollars.\n\n";
    while(play)
    {
    cout<<"Please select one of the following.\n"
    <<"1. Let's Play!\n"
    <<"2. How much dough do I got?\n"
    <<"3. Display values for spun items.\n"
    <<"4. Quit\n";
    cin>>choice;
    switch(choice)
    {
    case 1: pullwheel();
    case 2: cout<<money;
    case 3: cout<<disptable();
    case 4: play=0;
    default: cout<<"Are you a moron? Choose a number 1-4.";
    }
    }
    cout<<"You finished with $"<<money<<".\n\n";
    system("PAUSE");
    return 0;
    }

    int pullwheel()
    {
    int winnings;
    int item1;
    int item2;
    int item3;
    money=(money-5);
    item1=rand(time(NULL))%5;
    item2=rand(time(NULL))%5;
    item3=rand(time(NULL))%5;
    cout<<"You spun:\n";
    switch(item1)
    {
    case 0:cout<<"@ ";
    case 1:cout<<"# ";
    case 2:cout<<"* ";
    case 3:cout<<"& ";
    case 4:cout<<"^ ";
    }
    switch(item2)
    {
    case 0:cout<<"@ ";
    case 1:cout<<"# ";
    case 2:cout<<"* ";
    case 3:cout<<"& ";
    case 4:cout<<"^ ";
    }
    switch(item3)
    {
    case 0:cout<<"@";
    case 1:cout<<"#";
    case 2:cout<<"*";
    case 3:cout<<"&";
    case 4:cout<<"^";
    }
    if (item1==item2&&item2==item3&&item1==0)
    {winnings=5;}

    if (item1==item2&&item2==item3&&item1==1)
    {winnings=6;}

    if (item1==item2&&item2==item3&&item1==2)
    {winnings=8;}

    if (item1==item2&&item2==item3&&item1==3)
    {winnings=10;}

    if (item1==item2&&item2==item3&&item1==4)
    {winnings=12;}

    money=(money+winnings);

    cout<<"\n\nYou just won "<<winnings<<" dollars.\n"
    <<"You now have "<<money<<" dollars.\n\n";
    return 0;
    }

    int disptable()
    {cout<<"3 @'s returns $5, net gain=$0.\n"
    <<"3 #'s returns $6, net gain=$1.\n"
    <<"3 *'s returns $8, net gain=$3.\n"
    <<"3 &'s returns $10, net gain=$5.\n"
    <<"3 ^'s returns $12, net gain=$7.\n";
    return 0;
    }

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    2nd effort was much better. I've fixed your code. note the changes. Ask if you dont understand.
    Code:
    #include <iostream.h> 
    #include <time.h> 
    #include <stdlib.h> 
    
    int pullwheel(int&); 
    void disptable(); 
    
    int main() 
    {
    static int money=100;
    int play=1; 
    int choice;
    srand((unsigned)time(NULL)); 
    cout<<"Welcome to Neil's Virtual Slot Machine.\n" 
    <<"You will start with 100 dollars and the\n" 
    <<"amount you input is five dollars.\n\n"; 
    while(play) 
    { 
    cout<<"Please select one of the following.\n" 
    <<"1. Let's Play!\n" 
    <<"2. How much dough do I got?\n" 
    <<"3. Display values for spun items.\n" 
    <<"4. Quit\n"; 
    cin>>choice; 
    switch(choice) 
    { 
    case 1: pullwheel(money);
    		break;
    case 2: cout<<"You have $ "<<money<<endl;
    		break;
    case 3: disptable();
    		break;
    case 4: play=0;
    		break;
    default: cout<<"Are you a moron? Choose a number 1-4."; 
    } 
    } 
    cout<<"You finished with $"<<money<<".\n\n"; 
    system("PAUSE"); 
    return 0; 
    } 
    
    int pullwheel(int& money) 
    { 
    int winnings=0; 
    int item1; 
    int item2; 
    int item3; 
    money -= 5;
    item1=rand()%5; 
    item2=rand()%5; 
    item3=rand()%5; 
    cout<<"You spun:\n"; 
    switch(item1) 
    { 
    case 0:cout<<"@ ";
    		break;
    case 1:cout<<"# ";
    		break;
    case 2:cout<<"* ";
    		break;
    case 3:cout<<"& ";
    		break;
    case 4:cout<<"^ "; 
    		break;
    } 
    switch(item2) 
    { 
    case 0:cout<<"@ ";
    	break;
    case 1:cout<<"# ";
    	break;
    case 2:cout<<"* ";
    	break;
    case 3:cout<<"& ";
    	break;
    case 4:cout<<"^ "; 
    } 
    switch(item3) 
    { 
    case 0:cout<<"@";
    	break;
    case 1:cout<<"#";
    	break;
    case 2:cout<<"*";
    	break;
    case 3:cout<<"&"; 
    	break;
    case 4:cout<<"^"; 
    } 
    if (item1==item2&&item2==item3&&item1==0) 
    {winnings=5;} 
    
    if (item1==item2&&item2==item3&&item1==1) 
    {winnings=6;} 
    
    if (item1==item2&&item2==item3&&item1==2) 
    {winnings=8;} 
    
    if (item1==item2&&item2==item3&&item1==3) 
    {winnings=10;} 
    
    if (item1==item2&&item2==item3&&item1==4) 
    {winnings=12;} 
    
    money=(money+winnings); 
    
    cout<<"\n\nYou just won "<<winnings<<" dollars.\n" 
    <<"You now have "<<money<<" dollars.\n\n"; 
    return 0; 
    } 
    
    void disptable() 
    {
    cout<<"3 @'s returns $5, net gain=$0.\n" 
    <<"3 #'s returns $6, net gain=$1.\n" 
    <<"3 *'s returns $8, net gain=$3.\n" 
    <<"3 &'s returns $10, net gain=$5.\n" 
    <<"3 ^'s returns $12, net gain=$7."<<endl<<endl;  
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

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