#include <iostream>
using namespace std;

int main(){

	for (int i = 0; i < 1000; i++) {

	int die1, die2, roll1, roll2, point,;

	die1 = 1 + rand() % 6;
	die2 = 1 + rand() % 6;
	point = die1 + die2;
	

	cout << "You rolled: " << point << endl;

	if( point == 7 || point == 11 )
	{
		cout << "You win! Would you like to play again? ";
	}

	else if( point == 2 || point == 3 || point == 12 )
	{
		cout >> "Sorry you lose. Do you want to play agin? ";
	}

	return 0;
}

I got till here. I am getting lots of errors. I can only use the iostream, nothing else. I also need to let the player continue playing. Any help, please?

Ok, so now it's working. But i still don't know how to to continue playing if the player wants to play again. Please help!

//	Written by Khaled Alakhond
//	March 2, 2010
//	
//

#include <iostream>
using namespace std;

int main(){

	for (int i = 0; i < 1000; i++) {

	int die1, die2, roll1, roll2, point;
	

	die1 = 1 + rand() % 6;
	die2 = 1 + rand() % 6;
	point = die1 + die2;
	

	cout << "You rolled: " << point << endl;

	if( point == 7 || point == 11 )
	{
		cout << "You win! Would you like to play again? Enter y to play again. ";
		
	}

	else if( point == 2 || point == 3 || point == 12 )
	{
		cout << "Sorry you lose. Do you want to play agin? ";
	}
	}
	return 0;
}

Also, i am always getting 12. Why's that?

Put the code in a loop.

As for the 12, you need to look up the srand() function.

Ok, so now it's working. But i still don't know how to to continue playing if the player wants to play again. Please help!

//	Written by Khaled Alakhond
//	March 2, 2010
//	
//

#include <iostream>
using namespace std;

int main(){

	for (int i = 0; i < 1000; i++) {

	int die1, die2, roll1, roll2, point;
	

	die1 = 1 + rand() % 6;
	die2 = 1 + rand() % 6;
	point = die1 + die2;
	

	cout << "You rolled: " << point << endl;

	if( point == 7 || point == 11 )
	{
		cout << "You win! Would you like to play again? Enter y to play again. ";
		
	}

	else if( point == 2 || point == 3 || point == 12 )
	{
		cout << "Sorry you lose. Do you want to play agin? ";
	}
	}
	return 0;
}

- You need srand to seed your random number generator, otherwise you will ALWAYS get the same number unless you restart the program.
- Format your code a bit better. A shortcut to do this is:
ctrl + a
alt + F8
- To restart the whole function use a do-while loop. Avoid gotos.

Thanks alot guys! I got the srand to work. But now, i need to know how to keep the player to continue playing if he wants to.


Which loop should i use? Any help is appreciated.

//	
//

#include <iostream>
#include <time.h>
using namespace std;

int main(){
	

	int die1, die2, point;
	
	
	srand (time (NULL));

	die1 = 1 + rand() % 6;
	die2 = 1 + rand() % 6;
	point = die1 + die2;
	

	cout << "You rolled: " << point << endl;
	
	if( (point == 7) || (point == 11) )
	{
		cout << "You win! Would you like to play again? Enter y to play again. ";

	}

	else if( (point == 2) || (point == 3) || (point == 12) )
	{
		cout << "Sorry you lose. Do you want to play agin? ";
	}


	
		
	
	return 0;
}

Think about it. Don't expect us to hand you all the answers. What loop makes sense?

A while loop?

I got till here. But there is something infinite going on.

//	
//

#include <iostream>
#include <time.h>
using namespace std;

int main(){
	

	int die1, die2, point, y;
	
	
	srand (time (NULL));

	die1 = 1 + rand() % 6;
	die2 = 1 + rand() % 6;
	point = die1 + die2;
	
	cout << "You rolled: " << point << endl;

	while( point== 7 || point == 11 )
	{
		cout << "You win! Would you like to play again? Enter y to play again.";
		
		if( cin >> y )
		{
			point;
		}

	}


	
		
	
	return 0;
}

How do you exit the loop?
Do you want to roll the dice once then loop or do you want to roll the dice in the loop?

Please anybody help me!

I did. Or are you asking us to write it for you.

I really don't know. Please this is due in 2 hours, i need you to help me. I am begging you.

I repeat -- do you want to roll the dice only once in your program or for each turn?

For each turn.

I got till here.

But the problem is when i hit y, it just goes to an infinite loop showing the same number.

//

#include <iostream>
#include <time.h>
#include <iostream>
using namespace std;

int main(){
	
	char playagain;
	int die1, die2, point;
	
	
	srand (time (NULL));
	die1 = 1 + rand() % 6;
	die2 = 1 + rand() % 6;
	point = die1 + die2;
	
	cout << "You rolled: " << point << endl;

	
	if( point == 7 || point == 11 )
	{cout << "You win! Would you like to play again? Enter y to play again.   ";
	cin >> playagain;}
	else if ( point == 2 || point == 3 || point == 12 )
	{
		cout << "You lose. Would you like to play again? Enter y to play again.   ";
		cin >> playagain;
	}
	else
		cout << "Want to play again?";
		cin >> playagain;

	while ( playagain == 'y' )
	{
		cout << "You rolled: " << point << endl;
	}


		

	
	
		
	
	return 0;
}

Think. Where is your input? Where is your loop? Is your loop in the correct place?

I repeat -- Think! It's important when you write code.

Should i put it at the top? Before the input? Can you point that out to me?

Also, am i close to finishing it? Or do i still have a lot of work to do?

I get this, the variable 'playagain' is being used without being initialized. What's wrong?

//	
//	
//

#include <iostream>
#include <time.h>
#include <iostream>
using namespace std;

int main(){
	
	char playagain;
	int die1, die2, point;
	
	
	srand (time (NULL));
	die1 = 1 + rand() % 6;
	die2 = 1 + rand() % 6;
	point = die1 + die2;
	
	cout << "You rolled: " << point << endl;

	while ( playagain == 'y' )
	{

	if( point == 7 || point == 11 )
	{cout << "You win! Would you like to play again? Enter y to play again.   ";
	cin >> playagain;}
	else if ( point == 2 || point == 3 || point == 12 )
	{
		cout << "You lose. Would you like to play again? Enter y to play again.   ";
		cin >> playagain;
	}
	else
		cout << "Want to play again?";
		cin >> playagain;

	

	}
		

	
	
		
	
	return 0;
}

Should i put it at the top? Before the input? Can you point that out to me?

Stop answering a question with a question. The answer to my question is a simple yes or no. And if you answer that simple question, you will be closer to knowing what to do once you think about it.

I get this, the variable 'playagain' is being used without being initialized. What's wrong?

The first time you use playagain you are testing it. But what is it's value before that? It could be anything. You need to start it out with a value.

Now it's wrong. Please people, can anyone help me, it's do in less than 1 hour. I am in complete bad mental state right now.

//	
//	The purpose of this program is to make a simulate a game of craps.

#include <iostream>
#include <time.h>
#include <iostream>
using namespace std;

int main(){
	
	char playagain;
	int die1, die2, point;
	
	
	srand (time (NULL));
	die1 = 1 + rand() % 6;
	die2 = 1 + rand() % 6;
	point = die1 + die2;
	
	cout << "You rolled: " << point << endl;


	if( point == 7 || point == 11 )
	{
		cout << "You win! Would you like to play again? Enter y to play again.";
		cin >> playagain;
	}

	else if ( point == 2 || point == 3 || point == 12 )
	{
		cout << "You lose. Would you like to play again? Enter y to play again.   ";
		cin >> playagain;
	}

	else
		cout << "Want to play again?";
		cin >> playagain;
	


	
	return 0;
}

I am trying, nothing is working out. Please man, i am begging you give some bigger hints and information! I have 40 minutes left!

I'm getting this, but still infinite with same number!

//	The purpose of this program is to make a simulate a game of craps.

#include <iostream>
#include <time.h>
#include <iostream>
using namespace std;

int main(){
	
	char playagain;
	int die1, die2, point;
	
	playagain = 0;
	srand (time (NULL));
	die1 = 1 + rand() % 6;
	die2 = 1 + rand() % 6;
	point = die1 + die2;
	
	cout << "You rolled: " << point << endl;
		
	if( point == 7 || point == 11 )
	{
		cout << "You win! Would you like to play again? Enter y to play again.";
		cin >> playagain;
	}

	else if ( point == 2 || point == 3 || point == 12 )
	{
		cout << "You lose. Would you like to play again? Enter y to play again.   ";
		cin >> playagain;
	}

	else
		cout << "Want to play again?";
		cin >> playagain;
	
		while( playagain == 'y' )
		{
			cout << "You rolled: " << point << endl;
		}

	

	
	return 0;
}

PLEASE HELP ME PEOPLE! 20 minutes left. I'm on the verge of.....!

I'm still waiting for you to answer my question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.