|
|
|
#1 (permalink) | ||||||
|
PC Gamer
![]() |
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;
}
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
__________________
|
||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
Obscenely Green
![]() |
Code:
class 14;
cout<<"A";
break;
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
|
|||||||||||||
|
|
|
|
#3 (permalink) | ||||||
|
PC Gamer
![]() |
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
__________________
Last edited by computeruler : 11-16-09 at 09:50 PM |
||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
Obscenely Green
![]() |
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
|
|||||||||||||
|
|
|
|
#5 (permalink) | ||||||
|
PC Gamer
![]() |
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
__________________
|
||||||
|
|
|
|
|
#6 (permalink) | ||||||||||||
|
4.0ghz
![]() |
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.
__________________
|
||||||||||||
|
|
|
|
#7 (permalink) | ||||||
|
PC Gamer
![]() |
I am using a for loop now, and it works, but it just keeps outputing the same number 5 times instead of different ones.
__________________
|
||||||
|
|
|
|
|
#8 (permalink) | ||||||||||||
|
Overclocker
![]()
Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,999
Rep: 90
![]() Unique Rep: 80
Trader Rating: 0
|
post the code again, I'll help you out.
__________________
|
||||||||||||
|
|
|
|
|
#9 (permalink) | ||||||
|
PC Gamer
![]() |
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;
}
__________________
|
||||||
|
|
|
|
|
#10 (permalink) | ||||||||||||
|
Overclocker
![]()
Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,999
Rep: 90
![]() Unique Rep: 80
Trader Rating: 0
|
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;
}
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
__________________
Last edited by B-80 : 11-17-09 at 04:34 PM |
||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|