21 Card Game help
Posted: Thu Mar 29, 2007 5:00 pm
I've been working on a 21 card game for awhile, but I can't get it to work properly! It determines the winner fine but it outputs different totals then it displays in the last line, code is below. If anyone can help fix it up- its due tomorrow -that would be great!
Code: Select all
#include <iostream.h>
#include <H:/lvp/random.h>
int main()
{
// Variables
int numcard;
int youtotal;
int comptotal;
cout<<"Enter the number of cards you want: ";
cin>>numcard;
cout<<"You: ";
randomize;
for (int i=1; i<=numcard; i++)
cout<<random(10);
youtotal=random(10);
cout<<endl;
cout<<"Computer: ";
for (int a=1; a<=numcard; a++)
cout<<random(10);
comptotal=random(10);
cout<<endl;
//Detemine Winner and totals for you and the computer
cout<<"You have a total of ";
cout<<youtotal;
cout<<" and the computer has a total of ";
cout<<comptotal;
cout<<" therefore";
if (youtotal<21 && youtotal>comptotal) {
cout<<" you win."<<endl;
}
else if (comptotal<21 && comptotal>youtotal) {
cout<<" the computer wins."<<endl;
}
else {
cout<<"it is a draw."<<endl;
}
return(0);
}[code]
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:4765, old post ID:37654[/size][/color]