HELP Random Number Generator help

I just really need to know how to make a function in which a random number is given, until it is stopped. I have tried, but since I am a very large beginner, I do not know how. When I try it either says I have Run-time check failure #3, or it plays everything and repeats whats in the do-while loop over and over again. Please Help!



#include <iostream>;
#include <cstdlib> //drand function
#include <ctime> // time function
#include <Windows.h> //Sleep function
using namespace std;

/* *****************
Oscar, Zamora
1/20/13
This program was made
so that people can
understand and
experience how video
games are made using
the language of C++
***************** */

//start( float radius); //Function Prototype
//float volumes( float radius); // Function Prototype

int main()

{

int num;
char choicei = 'i';
char choiceh = 'h';
char choices = 's';
char choicec = 'c';
char choiceb = 'b';



// Welcome user to the introduction screen

cout << " BLACKJACK\n\n\n";
cout << " Thank youdsfafafd 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";

// Show the instructions

if (choicei = '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 (choicec = 'c')
{
cout << " The writer, producer, developer, and artist of this game is Oscar Zamora";
}

if (choiceb = 'b')
{
do
{

// 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;

//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 (choices = 's');
}
}
You should only call srand once at the start of your program, not every time it loops.

You should be using == for your if statements (comparison) not = (assignment).
How can I only use srand once if it is inside of my do-while loop?
It shouldn't be inside of your do-while loop. Put it right after the declaration of main. (rand() bases its value off of that, but it still only needs to be called once).
Did that but now my do-while loop is repeating itself nonstop!
You will need the user to enter in 'choices' at the end of the while loop every time to see if they want to continue, also don't forget to change those = errors.
It sill does not work. This is what have so far...
#include <iostream>;
#include <cstdlib> //drand function
#include <ctime> // time function
#include <Windows.h> //Sleep function
using namespace std;

/* *****************
Oscar, Zamora
1/20/13
This program was made
so that people can
understand and
experience how video
games are made using
the language of C++
***************** */

//start( float radius); //Function Prototype
//float volumes( float radius); // Function Prototype

int main()

{

int num;
char choicei = 'i';
char choiceh = 'h';
char choices = 's';
char choicec = 'c';
char choiceb = 'b';


// 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 youdsfafafd 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";

// Show the instructions

if (choicei == '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 (choicec == 'c')

{

cout << " The writer, producer, developer, and artist of this game is Oscar Zamora";

}

if (choiceb == '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 (choices == 's');
}
}
Topic archived. No new replies allowed.