It gives me this error which does not allow me to run my program. Also my program will keep repeating it's code.... what do I do? Please help i need to finish this and I don't understand coding very well. Please add anything to improve or correct my code. Also try it out and see what I'm dealing with here.
#include <iostream>;
#include <cstdlib> //drand function
#include <ctime> // time function
#include <Windows.h> //Sleep function
using namespace std;
int main()
{
int num;
int menuchoice;
char game;
float bet = 's';
// Suspend program for 2 seconds
Sleep(2000);
//seed random number ganerator using the system clock
srand(static_cast<unsigned int> (time(0)));
//generate a random number between 1 and 13
num = rand() % 13 + 1;
// Welcome user to the introduction screen
cout << " BLACKJACK\n\n\n";
cout << " Thank you for playing this game!\n\n";
cout << " Press 'b' to Start the game\n";
cout << " Press 'i' for intructions on the game\n";
cout << " Press 'c' for credits on the game\n";
cin >> menuchoice;
// Show the instructions
if (game == 'i')
{
cout << " The game you will be playing is called 'Blackjack' or 'twenty-one'.\n This is a multiplayer games in which one of the players want to get cards";
}
if (game == 'c')
{
cout << " The writer, producer, developer, and artist of this game";
}
if (game == 'b')
{
do
{
//Tell the user what card they got
cout << " You got" << num;
// Add up all the user"s cards and print
// Ask them if the y want to hit or stay
cout << " Would you like to get hit ('h') or stay ('s')";
//If they want to hit, loop back to generating a random number again otherwise let the computer get a hand
At a cursory glance I noticed two problems. Additionally, you should use the code tags to maintain formatting, making this a lot easier to read.
The first problem is rather minor, however the second problem is the likely culprit of what you are describing. Comments were inserted to show the problem, and were bolded
#include <iostream>; // Dont need a semicolon after the #include
#include <cstdlib> //drand function
#include <ctime> // time function
#include <Windows.h> //Sleep function
usingnamespace std;
int main()
{
int num;
int menuchoice;
char game;
float bet = 's';
// Suspend program for 2 seconds
Sleep(2000);
//seed random number ganerator using the system clock
srand(static_cast<unsignedint> (time(0)));
//generate a random number between 1 and 13
num = rand() % 13 + 1;
// Welcome user to the introduction screen
cout << " BLACKJACK\n\n\n";
cout << " Thank you for playing this game!\n\n";
cout << " Press 'b' to Start the game\n";
cout << " Press 'i' for intructions on the game\n";
cout << " Press 'c' for credits on the game\n";
cin >> menuchoice;
// Show the instructions
if (game == 'i') // the variable game is not initialized.
{
cout << " The game you will be playing is called 'Blackjack' or 'twenty-one'.\n This is a multiplayer games in which one of the players want to get cards";
}
if (game == 'c')
{
cout << " The writer, producer, developer, and artist of this game";
}
if (game == 'b')
{
do
{
//Tell the user what card they got
cout << " You got" << num;
// Add up all the user"s cards and print
// Ask them if the y want to hit or stay
cout << " Would you like to get hit ('h') or stay ('s')";
//If they want to hit, loop back to generating a random number again otherwise let the computer get a hand
}while (bet == 's');
}
}
If this fixes the problem please do say so. Ill have a more intimate look later.
#include <iostream>;
#include <cstdlib> //drand function
#include <ctime> // time function
#include <Windows.h> //Sleep function
usingnamespace std;
int main()
{
int num;
int menuchoice;
char game;
float bet = 's'; //int or float????
// Suspend program for 2 seconds
Sleep(2000);
//seed random number ganerator using the system clock
srand(static_cast<unsignedint> (time(0)));
//generate a random number between 1 and 13
num = rand() % 13 + 1;
// Welcome user to the introduction screen
cout << " BLACKJACK\n\n\n";
cout << " Thank you for playing this game!\n\n";
cout << " Press 'b' to Start the game\n";
cout << " Press 'i' for intructions on the game\n";
cout << " Press 'c' for credits on the game\n";
cin >> menuchoice;
// Show the instructions
//NOTE : "game" variable is unused.if (menuchoice == 'i') // if [game == 'i')
{
cout << " The game you will be playing is called 'Blackjack' or 'twenty-one'.\n This is a multiplayer games in which one of the players want to get cards";
}
if (menuchoice == 'c') // if [game == 'ic)
{
cout << " The writer, producer, developer, and artist of this game";
}
if (menuchoice == 'b') // if [game == 'b')
{
do
{
//Tell the user what card they got
cout << " You got" << num;
// Add up all the user"s cards and print -> What are user cards???
// You'll need to provide more information. "user card" variable?
// Ask them if the y want to hit or stay
cout << " Would you like to get hit ('h') or stay ('s')";
cin >> bet;
//If they want to hit, loop back to generating a random number again otherwise let the computer get a hand
num = rand() % 13 + 1; //???
//Be more specific. What is the variable you are looking for?
}while (bet == 's');
}
}
// Let Player 1 go first
cout << " Player 1's turn!!!";
// Tell the player what card they got
cout << " You got" << num;
// Add up all the user"s cards and print
// Ask them if the y want to hit or stay
cout << " Would you like to get hit ('h') or stay ('s')";
//If they want to hit, loop back to generating a random number again otherwise let the computer get a hand
cin >> choice;
}while (choice == 'h');
In the "Add up all the user's cards and print" the total is supposed to be 'num', but num has to be used for several different numbers, so how do I add all those 'nums' to make a 'total' ?
Why do we have 3 threads about the same thing? Don't do that - it's annoying because someone might write a long reply in one thread, only to find a whole lot has been written by others in one of the other ones.
but num has to be used for several different numbers, so how do I add all those 'nums' to make a 'total' ?