Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 11-16-09   #1 (permalink)
PC Gamer
 
computeruler's Avatar
 
intel ati

Join Date: Mar 2009
Posts: 1,227

Rep: 58 computeruler is acknowledged by some
Unique Rep: 50
Trader Rating: 1
Default high card game c++

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:
#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
__________________
Click below to show/hide Hidden Text Below!

We Are The Red Tide

Quote:
Originally Posted by Ecchi-BANZAII!!! View Post
Games look like it's 2004 again thanks to 360...
Quote:
Originally Posted by BlankThis View Post
Well I just got this nice comfy leather office chair from my dad. So about 2 hours ago I had a shower and after toweling off I got the urge to game... Don't ask why but naked.

But see here's the problem. I want to get up now but my behind is REALLY stuck to it... I think it's some kind of finish they put to the leather but I feel like I'm going to rip my skin off my.. you know...

Help?

~B~


System: archos 5 internet tablet
CPU
800 mhz ARM cortex
Memory
256 mb
Hard Drive
160 gb
Sound Card
430 mhz dsp
OS
android
computeruler is offline   Reply With Quote
Old 11-16-09   #2 (permalink)
Obscenely Green
 
nathris's Avatar
 
intel ati

Join Date: Sep 2007
Location: Canada
Posts: 8,299

Rep: 598 nathris is becoming famousnathris is becoming famousnathris is becoming famousnathris is becoming famousnathris is becoming famousnathris is becoming famous
Unique Rep: 453
Hardware Reviews: 1
Trader Rating: 0
Default

Code:
class 14;
      cout<<"A";
      break;
Should be

Code:
case 14:
      cout<<"A";
      break;

Its also never going to run because the condition statement in your while loop is wrong, and you're probably going to want to use a for loop.

Code:
for(int i = 0; i<5; i++) { }
__________________
Member of the Secret Cult of the F5F5F5. To join, copy this text into your signature

System: Yarr I be a pirate.
CPU
Core i5 750 @ 4.01/3.8GHz
Motherboard
EVGA P55-FTW
Memory
Corsair Dominator 2x2GB DDR3-1600 8-8-8-24
Graphics Card
XFX HD 4870 XXX (850/1040)
Hard Drive
WD6401AALS
Sound Card
Creative X-Fi Platinum Fatal1ty
Power Supply
Corsair HX750W
Case
CM690
CPU cooling
Corsair H50
GPU cooling
Twin Turbo + VRM-R2
OS
Windows 7 Pro x64
Monitor
Samsung 2443BW
nathris is offline Overclocked Account   Reply With Quote
Old 11-16-09   #3 (permalink)
PC Gamer
 
computeruler's Avatar
 
intel ati

Join Date: Mar 2009
Posts: 1,227

Rep: 58 computeruler is acknowledged by some
Unique Rep: 50
Trader Rating: 1
Default

so where would I put this for statment? And I think for some reason they have to be ; instead of : becuase that got rid of a bunch of errors
im a complete noob at this stuff
__________________
Click below to show/hide Hidden Text Below!

We Are The Red Tide

Quote:
Originally Posted by Ecchi-BANZAII!!! View Post
Games look like it's 2004 again thanks to 360...
Quote:
Originally Posted by BlankThis View Post
Well I just got this nice comfy leather office chair from my dad. So about 2 hours ago I had a shower and after toweling off I got the urge to game... Don't ask why but naked.

But see here's the problem. I want to get up now but my behind is REALLY stuck to it... I think it's some kind of finish they put to the leather but I feel like I'm going to rip my skin off my.. you know...

Help?

~B~


System: archos 5 internet tablet
CPU
800 mhz ARM cortex
Memory
256 mb
Hard Drive
160 gb
Sound Card
430 mhz dsp
OS
android

Last edited by computeruler : 11-16-09 at 09:50 PM
computeruler is offline   Reply With Quote
Old 11-17-09   #4 (permalink)
Obscenely Green
 
nathris's Avatar
 
intel ati

Join Date: Sep 2007
Location: Canada
Posts: 8,299

Rep: 598 nathris is becoming famousnathris is becoming famousnathris is becoming famousnathris is becoming famousnathris is becoming famousnathris is becoming famous
Unique Rep: 453
Hardware Reviews: 1
Trader Rating: 0
Default

for loop replaces the do while and count.

What I would do is have a variable for the highest card in the hand, then in the for loop compare the next card with the current highest and if its higher then replace it.

Do that for each hand and then compare the highest values to see who wins.

And when you are debugging only focus on the first error, as it is usually causing the other errors.
__________________
Member of the Secret Cult of the F5F5F5. To join, copy this text into your signature

System: Yarr I be a pirate.
CPU
Core i5 750 @ 4.01/3.8GHz
Motherboard
EVGA P55-FTW
Memory
Corsair Dominator 2x2GB DDR3-1600 8-8-8-24
Graphics Card
XFX HD 4870 XXX (850/1040)
Hard Drive
WD6401AALS
Sound Card
Creative X-Fi Platinum Fatal1ty
Power Supply
Corsair HX750W
Case
CM690
CPU cooling
Corsair H50
GPU cooling
Twin Turbo + VRM-R2
OS
Windows 7 Pro x64
Monitor
Samsung 2443BW
nathris is offline Overclocked Account   Reply With Quote
Old 11-17-09   #5 (permalink)
PC Gamer
 
computeruler's Avatar
 
intel ati

Join Date: Mar 2009
Posts: 1,227

Rep: 58 computeruler is acknowledged by some
Unique Rep: 50
Trader Rating: 1
Default

I just realized that it should be case....

ill try and see if I can do what you said though
That would be a lot easier
__________________
Click below to show/hide Hidden Text Below!

We Are The Red Tide

Quote:
Originally Posted by Ecchi-BANZAII!!! View Post
Games look like it's 2004 again thanks to 360...
Quote:
Originally Posted by BlankThis View Post
Well I just got this nice comfy leather office chair from my dad. So about 2 hours ago I had a shower and after toweling off I got the urge to game... Don't ask why but naked.

But see here's the problem. I want to get up now but my behind is REALLY stuck to it... I think it's some kind of finish they put to the leather but I feel like I'm going to rip my skin off my.. you know...

Help?

~B~


System: archos 5 internet tablet
CPU
800 mhz ARM cortex
Memory
256 mb
Hard Drive
160 gb
Sound Card
430 mhz dsp
OS
android
computeruler is offline   Reply With Quote
Old 11-17-09   #6 (permalink)
4.0ghz
 
hometoast's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Pennsylvania
Posts: 2,633
Blog Entries: 3

Rep: 205 hometoast is acknowledged by manyhometoast is acknowledged by manyhometoast is acknowledged by many
Unique Rep: 163
Folding Team Rank: 193
Hardware Reviews: 3
Trader Rating: 19
Default

Definitely replace the do/while with a for loop. You could be waiting a long time for random() to spit out one of your numbers.

System: whuddamess
CPU
Q9550
Motherboard
EP45-UD3P
Memory
4GB
Graphics Card
2x GTX260
Hard Drive
320GB
Sound Card
Xfi XtremeMusic
Power Supply
600W
Case
CM Cosmos 1000
CPU cooling
Xig Dark Knight
OS
Win7
Monitor
20"
1 Million+ Folding at Home points
hometoast is offline I fold for Overclock.net Overclocked Account   Reply With Quote
Old 11-17-09   #7 (permalink)
PC Gamer
 
computeruler's Avatar
 
intel ati

Join Date: Mar 2009
Posts: 1,227

Rep: 58 computeruler is acknowledged by some
Unique Rep: 50
Trader Rating: 1
Default

I am using a for loop now, and it works, but it just keeps outputing the same number 5 times instead of different ones.
__________________
Click below to show/hide Hidden Text Below!

We Are The Red Tide

Quote:
Originally Posted by Ecchi-BANZAII!!! View Post
Games look like it's 2004 again thanks to 360...
Quote:
Originally Posted by BlankThis View Post
Well I just got this nice comfy leather office chair from my dad. So about 2 hours ago I had a shower and after toweling off I got the urge to game... Don't ask why but naked.

But see here's the problem. I want to get up now but my behind is REALLY stuck to it... I think it's some kind of finish they put to the leather but I feel like I'm going to rip my skin off my.. you know...

Help?

~B~


System: archos 5 internet tablet
CPU
800 mhz ARM cortex
Memory
256 mb
Hard Drive
160 gb
Sound Card
430 mhz dsp
OS
android
computeruler is offline   Reply With Quote
Old 11-17-09   #8 (permalink)
Overclocker
 
B-80's Avatar
 
intel nvidia

Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,999

Rep: 90 B-80 is acknowledged by some
Unique Rep: 80
Trader Rating: 0
Default

post the code again, I'll help you out.
__________________

Aumotocnic"An unfortunate member of the overclock.net insomnia club"

-- / T_he Rad / iohead F_a/n Club_--

Crucial Ballistix Club

System: The Mediocre Guy
CPU
E7200 @ 3.8ghz
Motherboard
Gigabyte P45 DS3
Memory
4GB Corsair XMS2
Graphics Card
Geforce 8800 GTS (600/900)
Hard Drive
250 gb hitachi Deskstar + 120gb Seagate
Power Supply
PC Power & Cooling Silencer 750 Quad
Case
Aspire X-Cruiser Black
CPU cooling
Zalman 9700
GPU cooling
Stock
OS
Ubuntu
Monitor
ViewSonic Optiquest 20.1 inch 1650x1058
B-80 is offline   Reply With Quote
Old 11-17-09   #9 (permalink)
PC Gamer
 
computeruler's Avatar
 
intel ati

Join Date: Mar 2009
Posts: 1,227

Rep: 58 computeruler is acknowledged by some
Unique Rep: 50
Trader Rating: 1
Default

Code:
#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 ";
            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;
}
__________________
Click below to show/hide Hidden Text Below!

We Are The Red Tide

Quote:
Originally Posted by Ecchi-BANZAII!!! View Post
Games look like it's 2004 again thanks to 360...
Quote:
Originally Posted by BlankThis View Post
Well I just got this nice comfy leather office chair from my dad. So about 2 hours ago I had a shower and after toweling off I got the urge to game... Don't ask why but naked.

But see here's the problem. I want to get up now but my behind is REALLY stuck to it... I think it's some kind of finish they put to the leather but I feel like I'm going to rip my skin off my.. you know...

Help?

~B~


System: archos 5 internet tablet
CPU
800 mhz ARM cortex
Memory
256 mb
Hard Drive
160 gb
Sound Card
430 mhz dsp
OS
android
computeruler is offline   Reply With Quote
Old 11-17-09   #10 (permalink)
Overclocker
 
B-80's Avatar
 
intel nvidia

Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,999

Rep: 90 B-80 is acknowledged by some
Unique Rep: 80
Trader Rating: 0
Default

okay your generating the same random number... try this

Code:
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main ()
{
    int random1=0, random2=0, count=0;
    cout<<"Your cards are ";
	srand(time(NULL));
    for (;count<5;count++)
    {
			
			int 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;
}
your problems were, you called srand again in the loop.
srand using the time will only give you a different seed every second, since the loop executes much faster than that, you kept getting the same random number.

also, your modulus division returned values from 1-14, not 2-14

edit: that's why it would output 4 numbers sometimes, you didn't have a case for 1
__________________

Aumotocnic"An unfortunate member of the overclock.net insomnia club"

-- / T_he Rad / iohead F_a/n Club_--

Crucial Ballistix Club

System: The Mediocre Guy
CPU
E7200 @ 3.8ghz
Motherboard
Gigabyte P45 DS3
Memory
4GB Corsair XMS2
Graphics Card
Geforce 8800 GTS (600/900)
Hard Drive
250 gb hitachi Deskstar + 120gb Seagate
Power Supply
PC Power & Cooling Silencer 750 Quad
Case
Aspire X-Cruiser Black
CPU cooling
Zalman 9700
GPU cooling
Stock
OS
Ubuntu
Monitor
ViewSonic Optiquest 20.1 inch 1650x1058

Last edited by B-80 : 11-17-09 at 04:34 PM
B-80 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 01:01 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2010 Shogun Interactive Development. Most rights reserved.
Page generated in 0.18377 seconds with 8 queries