hi pll
with all this post im makin ill probably look like i only have problems :S, but well, books dont solve all my problems :S

so....
my todays problem is that i have to make a game that uses the random values of two dices, n accordin to the result of the sum up of them, the user, wins, losses or has to keep goin till he reaches the value he got at first place.
so its like this: for 7 n 11 at first shot, he wins, for numers 4, 5, 6, 8, 9 n 10, has to keep playing until gettin the same number, but if he gets 2, 3 or 12, he losses.
for the 4, 5, 6, 8, 9 n 10, will keep playing unless he gets a 7, wich means he losses again.

the first part, i got it n works perfectly, i mean, the dices have random values, they sum up right, n the messages that have to show, they show how they should.
the problem is when i have those number to keep playin, tried to put the code in different places, but doesnt take it.

``````// dados_ _ej-a-entregar.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <time.h>      //sirve para cuando se va a trabajar con horas

int _tmain(int argc, _TCHAR* argv[])
{
srand (time(NULL));       // para que tome la hora de la pc como numero random

using namespace std;

int d1, d2;
int suma = 0, punto = 0;   // para valores de los dados
char game;

d1 = rand () % 6 + 1;     // para que de los numeros de los dados en forma aleatoria
d2 = rand () % 6 + 1;     // para que de los numeros de los dados en forma aleatoria

cout << " Wanna start?? " << "\n";
cout << "     1 - YES, OF COURSE jeje" << "\n";
cout << "     2 - NO, GET ME OUT OF HERE" << "\n";
cout << "                                ";
cin >> game;

while (game != '2')
{
cout << "  first dice is...  ";
cout << d1;
cout << "\n" << "\n";

cout << "  second dice is...  ";
cout << d2;
cout << "\n" << "\n" << "\n";

suma = d1 + d2;

cout << "  the sum up is...: " << suma << "\n" << "\n";

switch (suma)
{
case 11:
cout << " YOU WON " << "\n" << "\n" << "\n" << "\n";
break;
case 7:
cout << " YOU WON " << "\n" << "\n" << "\n" << "\n";
break;
case 2:
cout << " YOU LOST " << "\n" << "\n" << "\n" << "\n";
break;
case 3:
cout << " YOU LOST " << "\n" << "\n" << "\n" << "\n";
break;
case 12:
cout << " YOU LOST " << "\n" << "\n" << "\n" << "\n";
break;
case 4:
cout << " 4 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 5:
cout << " 5 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 6:
cout << " 6 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 8:
cout << " 8 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 9:
cout << " 9 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 10:
cout << " 10 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
default:    // I HAVE PROBLEMS WITH THIS
while ((suma = punto) && (suma !=7))
{
d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly

suma = d1 + d2;

switch (suma)
{
case 4:
cout << " 4 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 5:
cout << " 5 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 6:
cout << " 6 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 8:
cout << " 8 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 9:
cout << " 9 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 10:
cout << " 10 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
break;
case 7:
cout << " YOU LOST";                //TILL HERE. THIS IS THE CODE TO KEEP PLAYIN THAT DOESNT WORK
}
}
}

cout << " Wanna play again?? " << "\n";
cout << "     1 - YES, OF COURSE jeje" << "\n";
cout << "     2 - NO, GET ME OUT OF HERE" << "\n";
cout << "                                ";
cin >> game;
cout << "\n" << "\n" << "\n" << "\n";

d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly
}

system ("PAUSE");
return 0;
}``````

the program is atached

tnks!! :P

> while ((suma = punto) && (suma !=7))
Perhaps you meant ==

thanks for that, didnt realiced!!

but my problem still persist
doesnt do anything when user "has a point", it should keep showing numbers till the sum up is 7 or is equal to the number that had at the begining

maybe i wasnt clear

I believe do-while will serve you better than while(). You need not repeat 25 - 29 if you use do-while loop
Could you explain how the game works? so that I can think of a solution.

the game is:
a player trows two dices.
If the sum of the numbers obtained in the first shot is 7 or 11 he wins. If it is 2, 3 or 12 he loses. And if it was 4, 5, 6, 8, 9 or 10, then the sum becomes "point" of the player and must continue throwing up to coming to his point. The player loses on having thrown 7 before coming to the point.

the first part works (until he has to continue trowing) but then, i wrote the code, but doesnt work.

cuz it should take only the numbers that are "point", so i dont know if what i wrote i right or i have to do a do while loop in every number

I still don't understand part of the game. Is this what the game should do?

``````#include <iostream>
#include <time.h>
int main(int argc, char* argv[])
{
srand (time(NULL));
using namespace std;
int d1, d2;
int suma = 0, punto = 0;
char game;
cout << " Wanna start ?? \n";
cout << " 1 - YES, OF COURSE jeje\n";
cout << " 2 - NO, GET ME OUT OF HERE\n Your Choice: ";
cin >> game;
while (game != '2')
{
cin.get() ;
d1 = rand () % 6 + 1;
d2 = rand () % 6 + 1;
cout << "\n first dice is...  " << d1 << "\n\n";
cout << " second dice is...  " << d2 << "\n\n";
cout << " the sum up is... " << (suma = d1+d2) << "\n\n";

switch (suma)
{
case 11: case 7:
cout << " YOU WON \n\n";
break;
case 2: case 3: case 12:
cout << " YOU LOST \n\n";
break;
case 5: case 4:	case 6: case 8: case 9: case 10:
cout << " " << suma << " is your point \n\n";
punto = suma ;
bool flag = false ;
do
{
cout << " Press Enter to throw again... ";
cin.get() ;
d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly
cout << "\n first dice is...  " << d1 << "\n\n";
cout << " second dice is...  " << d2 << "\n\n";
cout << " the sum up is... " << (suma = d1+d2) << "\n\n";
if ( suma == punto ) cout << endl << " You Won", flag = true ;
else if ( suma == 7 )cout << endl << " YOU LOST", flag = true;
}while (flag!= true) ;
break ;
}
cout << "\n Wanna start again?? \n";
cout << " 1 - YES, OF COURSE jeje\n";
cout << " 2 - NO, GET ME OUT OF HERE" << "\n Your Choice: ";
cin >> game;
}
cin.get() ;
return 0;
}``````

I modified your code with what i understood about the game. Hope this helps:)

hi,
im back here again, ive modified the code, so it reads some more thows, until 7 arrives. problem now is that when the number i got at the beginin appears a message should appear sayin i got it. but it doesnt.
here i copy the new code, with the modifications, also i attach the program and a screen with the results and whats suposed to do.

``````// dados_ _ej-a-entregar.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <time.h>      //sirve para cuando se va a trabajar con horas

int _tmain(int argc, _TCHAR* argv[])
{
srand (time(NULL));       // para que tome la hora de la pc como numero random

using namespace std;

int d1, d2;
int suma = 0, punto = 0;   // para valores de los dados
char game;

d1 = rand () % 6 + 1;     // para que de los numeros de los dados en forma aleatoria
d2 = rand () % 6 + 1;     // para que de los numeros de los dados en forma aleatoria

cout << " Wanna start?? " << "\n";
cout << "     1 - YES, OF COURSE jeje" << "\n";
cout << "     2 - NO, GET ME OUT OF HERE" << "\n";
cout << "                                ";
cin >> game;

while (game != '2')
{
cout << "  first dice is...  ";
cout << d1;
cout << "\n";

cout << "  second dice is...  ";
cout << d2;
cout << "\n";

suma = d1 + d2;

cout << "  the sum up is...: " << suma << "\n" << "\n";

switch (suma)
{
case 11:
cout << " YOU WON " << "\n" << "\n" << "\n" << "\n";
break;
case 7:
cout << " YOU WON " << "\n" << "\n" << "\n" << "\n";
break;
case 2:
cout << " YOU LOST " << "\n" << "\n" << "\n" << "\n";
break;
case 3:
cout << " YOU LOST " << "\n" << "\n" << "\n" << "\n";
break;
case 12:
cout << " YOU LOST " << "\n" << "\n" << "\n" << "\n";
break;
case 4:
cout << " 4 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
do
{
d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly

suma = d1 + d2;
cout << "  the sum up is...: " << suma << "\n" << "\n";

if (suma == 7)
cout << " YOU LOST, U REACHED 7 BEFORE REACHIN 10" << "\n" << "\n" << "\n" << "\n";
if (suma == punto)
cout << " YOU REACHED UR POINT " << "\n" << "\n" << "\n" << "\n";
}
while ((suma != 7));
break;
case 5:
cout << " 5 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
do
{
d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly

suma = d1 + d2;
cout << "  the sum up is...: " << suma << "\n" << "\n";

if (suma == 7)
cout << " YOU LOST, U REACHED 7 BEFORE REACHIN 10" << "\n" << "\n" << "\n" << "\n";
if (suma == punto)
cout << " YOU REACHED UR POINT " << "\n" << "\n" << "\n" << "\n";
}
while ((suma != 7));
break;
case 6:
cout << " 6 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
do
{
d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly

suma = d1 + d2;
cout << "  the sum up is...: " << suma << "\n" << "\n";

if (suma == 7)
cout << " YOU LOST, U REACHED 7 BEFORE REACHIN 10" << "\n" << "\n" << "\n" << "\n";
if (suma == punto)
cout << " YOU REACHED UR POINT " << "\n" << "\n" << "\n" << "\n";
}
while ((suma != 7));
break;
case 8:
cout << " 8 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
do
{
d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly

suma = d1 + d2;
cout << "  the sum up is...: " << suma << "\n" << "\n";

if (suma == 7)
cout << " YOU LOST, U REACHED 7 BEFORE REACHIN 10" << "\n" << "\n" << "\n" << "\n";
if (suma == punto)
cout << " YOU REACHED UR POINT " << "\n" << "\n" << "\n" << "\n";
}
while ((suma != 7));
break;
case 9:
cout << " 9 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
do
{
d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly

suma = d1 + d2;
cout << "  the sum up is...: " << suma << "\n" << "\n";

if (suma == 7)
cout << " YOU LOST, U REACHED 7 BEFORE REACHIN 10" << "\n" << "\n" << "\n" << "\n";
if (suma == punto)
cout << " YOU REACHED UR POINT " << "\n" << "\n" << "\n" << "\n";
}
while ((suma != 7));
break;
case 10:
cout << " 10 is your point " << "\n" << "\n" << "\n" << "\n";
suma = punto;
do
{
d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly

suma = d1 + d2;
cout << "  the sum up is...: " << suma << "\n" << "\n";

if (suma == 7)
cout << " YOU LOST, U REACHED 7 BEFORE REACHIN 10" << "\n" << "\n" << "\n" << "\n";
if (suma == punto)
cout << " YOU REACHED UR POINT " << "\n" << "\n" << "\n" << "\n";
}
while ((suma != 7));
}

cout << " Wanna play again?? " << "\n";
cout << "     1 - YES, OF COURSE jeje" << "\n";
cout << "     2 - NO, GET ME OUT OF HERE" << "\n";
cout << "                                ";
cin >> game;
cout << "\n" << "\n" << "\n" << "\n";

d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly
}

system ("PAUSE");
return 0;
}``````

Did you run my program?
I hope removing unnecessary output statements should help you get the desired output:)

I still don't understand part of the game. Is this what the game should do?

``bool flag = false ;``

Prabakar, which part didn u understand??

And the bool flag what does it do???
Sorry, I make lots of questions, ive just started with c++ :S

by the way; i just uploaded a new code, dont know if thats correct, but ill try urs n then ill let u know!!

Well the .bmp file explain it. I guess my the code should work fine.
flag is just a variable that I set to false(0) initially & if 7 or the point is reached flag is set to true(1) & hence exits out of the loop. you can set something like this too
int flag = 0 ;
and set it to 1 when conditions are met so that you can exit the loop
So is this code ok?

``````#include <iostream>
#include <time.h>
int main()
{
srand (time(NULL));
using namespace std;
int d1, d2;
int suma = 0, punto = 0;
char game;
cout << " Wanna start ?? \n";
cout << " 1 - YES, OF COURSE jeje\n";
cout << " 2 - NO, GET ME OUT OF HERE\n Your Choice: ";
cin >> game;
while (game != '2')
{
cin.get() ;
d1 = rand () % 6 + 1;
d2 = rand () % 6 + 1;
cout << "\n first dice is...  " << d1 << "\n\n";
cout << " second dice is...  " << d2 << "\n\n";
cout << " the sum up is... " << (suma = d1+d2) << "\n\n";

switch (suma)
{
case 11: case 7:
cout << " YOU WON \n\n";
break;
case 2: case 3: case 12:
cout << " YOU LOST \n\n";
break;
case 5: case 4:	case 6: case 8: case 9: case 10:
cout << " " << suma << " is your point \n\n";
punto = suma ;
bool flag = false ;
do
{
d1 = rand () % 6 + 1;     // to dice start randomly
d2 = rand () % 6 + 1;     // to dice start randomly
cout << " the sum up is... " << (suma = d1+d2) << "\n\n";
if ( suma == punto )
cout << endl << " You Won", flag = true ;
else if ( suma == 7 )
cout << endl << " YOU LOST", flag = true;
}while (flag!= true) ;
break ;
}
cout << "\n Wanna start again?? \n";
cout << " 1 - YES, OF COURSE jeje\n";
cout << " 2 - NO, GET ME OUT OF HERE" << "\n Your Choice: ";
cin >> game;
}
cin.get() ;
return 0;
}``````

thanks a lot!!

that worked out perfectly!!!

:D:D:D:D:D:D

Prabakar :
one last question: the cin.get()
is used to get some extra enter or whatever the user writes, right??

gispe!!

For some reason I was never notified that you have replied.

And yes, I used it to get '\n' in the first program. In the second program I forgot to delete it:P