Home / Software / Computer programming / high card game c++
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: high card game c++  (Read 688 times)
computeruler
Topic Starter
Egghead



Thanked: 63
Posts: 3,393

Experience: Experienced
OS: Windows XP

1
« on: November 16, 2009, 06:14:13 PM »

For schoo we have to make a program that outputs 5 cards and says what the highest is like

your cards are 1 6 3 A K
your highest is A
the computers cards are 4 5 2 Q J
The computers highest card is Q
You win!

We have to do it using a loop, so we cant just use 5 randoms. Now the problem I was having at school was that it would sometimes just output 4 numbers instead of 5. I tried to recreate the code here at home but it didn't work so well. Although I do have visual c++ 08 express edition and at school they have a 05 version. But anyways heres what I have do far

Code: [Select]
#include <iostream>
#include <ctime>
using namespace std;
int main ()
{
    int random1=0, random2=0, count=5;

cout<<"Your cards are ";

    do
    {
       
        srand(time(0));
            random1 = rand()%14+1;
        count++;
           
        cout<<""<<random1<<"";

        switch(random1)
        {
           
            class 2;
                cout<<"2";
            break;
            class 3;
                cout<<"3";
            break;
            class 4;
                cout<<"4";
            break;
            class 5;
                cout<<"5";
            break;
            class 6;
                cout<<"6";
            break;
            class 7;
                cout<<"7";
            break;
            class 8;
                cout<<"8";
            break;
            class 9;
                cout<<"9"<<endl;
            break;
            class 10;
                cout<<"10";
            break;
            class 11;
                cout<<"J";
            break;
            class 12;
                cout<<"Q";
            break;
            class 13;
                cout<<"K";
            break;
            class 14;
                cout<<"A";
            break;
            }
    }while (count < 0);

return 0;
}
now Im getting tons of errors for some reason.

Error 2 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 22

Error 4 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 22

Error 5 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 25

Error 7 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 25
Error 8 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 28

Error 10 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 28
Error 11 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 31

Error 13 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 31

Error 14 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 34

Error 16 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 34

Error 17 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 37

Error 19 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 37

Error 20 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 40

Error 22 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 40

Error 23 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 43

Error 25 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 43

Error 26 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 46

Error 28 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 46

Error 29 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 49

Error 31 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 49

Error 32 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 52

Error 34 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 52

Error 35 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 55

Error 37 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 55

Error 38 error C2332: 'class' : missing tag name c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 58

Error 40 error C2143: syntax error : missing ';' before 'constant' c:\users\computeruler\documents\visual studio 2008\projects\high card\high card\high card.cpp 58
IP logged

BC_Programmer
Mastermind


Thanked: 682
Posts: 15,624

Computer: Specs
Experience: Beginner
OS: Windows 7


Pinkie Pie is best pony

BC-Programming.com 1 1
« Reply #1 on: November 16, 2009, 10:12:39 PM »

2008 Professional Here.


Mostly syntax errors.

It's "case" not class, and you should end each case with a colon...


Code: [Select]


#include <iostream>
#include <ctime>
using namespace std;
int main()
{





    int random1=0, random2=0, count=5;

cout<<"Your cards are " << endl;

    do
    {
       
        srand(time(0));
            random1 = rand()%14+1;
        count++;
           
        cout << "" << random1;

        switch(random1)
        {
           
case 2:
                cout<<"2";
            break;
case 3:
                cout<<"3";
            break;
case 4:
                cout<<"4";
            break;
case 5:
                cout<<"5";
            break;
case 6:
                cout<<"6";
            break;
case 7:
                cout<<"7";
            break;
case 8:
                cout<<"8";
            break;
case 9:
                cout<<"9"<<endl;
            break;
case 10:
                cout<<"10";
            break;
case 11:
                cout<<"J";
            break;
case 12:
                cout<<"Q";
            break;
case 13:
                cout<<"K";
            break;
case 14:
                cout<<"A";
            break;
            }
    }while (count < 0);

return 0;

}



IP logged

computeruler
Topic Starter
Egghead



Thanked: 63
Posts: 3,393

Experience: Experienced
OS: Windows XP

1
« Reply #2 on: November 17, 2009, 04:49:01 AM »

*smacks head
anyways, it got rid of errors with ; but changing it to case should do it
IP logged

computeruler
Topic Starter
Egghead



Thanked: 63
Posts: 3,393

Experience: Experienced
OS: Windows XP

1
« Reply #3 on: November 17, 2009, 12:52:18 PM »

Now im having a problem were it will only ouput the same number
I also changed the do while to a for
Code: [Select]
#include <iostream>
#include <ctime>
using namespace std;
int main ()
{
int random1=0, random2=0, count=0;
cout<<"Your cards are ";
for (;count<5;count++)
{
srand(time(0));
random1 = rand()%14+1;

switch(random1)
{
case 2:
cout<<"2 ";
break;
case 3:
cout<<"3 ";
break;
case 4:
cout<<"4 ";
break;
case 5:
cout<<"5 ";
break;
case 6:
cout<<"6 ";
break;
case 7:
cout<<"7 ";
break;
case 8:
cout<<"8 ";
break;
case 9:
cout<<"9 "<<endl;
break;
case 10:
cout<<"10 ";
break;
case 11:
cout<<"J ";
break;
case 12:
cout<<"Q ";
break;
case 13:
cout<<"K ";
break;
case 14:
cout<<"A ";
break;
}

}

return 0;
}
IP logged

computeruler
Topic Starter
Egghead



Thanked: 63
Posts: 3,393

Experience: Experienced
OS: Windows XP

1
« Reply #4 on: November 17, 2009, 07:14:44 PM »

Ok, I got that fixed and now I have no idea how to find the highest
Any ideas?

Code: [Select]
#include <iostream>
#include <ctime>
using namespace std;
int main ()
{
int random1=0, random2=0, count=0;
cout<<"Your cards are ";
srand(time(0));

for (;count<5;count++)
{

random1 = rand()%13+2;
switch(random1)
{
case 2:
cout<<"2 ";
break;
case 3:
cout<<"3 ";
break;
case 4:
cout<<"4 ";
break;
case 5:
cout<<"5 ";
break;
case 6:
cout<<"6 ";
break;
case 7:
cout<<"7 ";
break;
case 8:
cout<<"8 ";
break;
case 9:
cout<<"9 ";
break;
case 10:
cout<<"10 ";
break;
case 11:
cout<<"J ";
break;
case 12:
cout<<"Q ";
break;
case 13:
cout<<"K ";
break;
case 14:
cout<<"A ";
break;
}

}

return 0;
}
IP logged

computeruler
Topic Starter
Egghead



Thanked: 63
Posts: 3,393

Experience: Experienced
OS: Windows XP

1
« Reply #5 on: November 18, 2009, 03:43:01 PM »

nvm I got it working
IP logged

Pages: [1] - (Top) Print 
Home / Software / Computer programming / high card game c++ « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.122 seconds with 20 queries.