Solved

how do i get the program to loop around if they press enter

Posted on 2004-10-11
4
191 Views
Last Modified: 2010-04-01
in the switch statement where it says please roll again i want the user to be able to press enter and then the dice to roll again


      cout << "Welcome to CRAPS\n\n"  <<  endl;
      
      cout << "Please pleace your bet" << endl;      
      cin  >> Bet;


while(TotalMoney >= 0){




cout << "Point " << Point;      
cout << "Counter " << Counter;
srand(time(0));
Dice1 = 1 + rand() % 6;
Dice2 = 1 + rand() % 6;




SumOfDice = Dice1 + Dice2;
cout << "You rolled a sum of " << SumOfDice << endl;




      

Counter = ++Counter;

case 2:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
      
break;
      }
0
Comment
Question by:tedschnieders
4 Comments
 
LVL 3

Accepted Solution

by:
aravindtj earned 500 total points
ID: 12278509
Put the following statments before the end of while loop.

flush(stdin);
while (getch() == '\n');

this will loop forever while you press enter key.

all the best.
0
 
LVL 12

Expert Comment

by:stefan73
ID: 12278644
Hi tedschnieders,
Don't mix C stdio with C++ IO. Use either.

Cheers!

Stefan
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 12278830
Include <string> and use getline to read into a junk string.
0
 

Author Comment

by:tedschnieders
ID: 12280316
i have to do this is an assignment and i have been worken on it forever.........it sucks

i dont know programming enough could someone compile this and and show me how to finish this

if they roll there point it keeps looping til they when or lose but i want them to have to press enter to get the dice to show up again
hopefully you get what i am talken about ccause im not sure if i know

thank you much
ted

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>

using namespace std;

int main(){
int Dice1        = 0;
int Dice2        = 0;
float Bet        = 0;
int Point        = 0;
int SumOfDice    = 0;
float TotalMoney = 1000;
int Counter = 0;

      cout << "Welcome to CRAPS\n\n"  <<  endl;
      
      cout << "Please pleace your bet" << endl;      
      cin  >> Bet;

srand(time(0));

while(TotalMoney > 0){




cout << "Point " << Point;      
cout << "Counter " << Counter;

Dice1 = 1 + rand() % 6;
Dice2 = 1 + rand() % 6;

SumOfDice = Dice1 + Dice2;
cout << "You rolled a sum of " << SumOfDice << endl;

Counter = ++Counter;




      
switch(Dice1){

case 1:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*          *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 2:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*            *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 3:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 4:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 5:
      cout <<      "\n***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*     *   *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 6:
      cout <<      "\n***********\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "***********\n";
break;
}      
switch(Dice2){

case 1:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*          *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 2:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*            *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 3:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *        *\n";
      cout <<      "*    *        *\n";
      cout <<      "*      *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 4:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*         *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 5:
      cout <<      "***********\n";
      cout <<      "*         *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*     *   *\n";
      cout <<      "*  *      * *\n";
      cout <<      "*          *\n";
      cout <<      "***********\n";
      break;
case 6:
      cout <<      "***********\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "*          *\n";
      cout <<      "*  *   *  *\n";
      cout <<      "***********\n";
break;
      }
                  
switch(SumOfDice){

case 2:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
      

break;
      }
case 3:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
break;
      }

case 4:      
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;      
      }
      else if(Counter > 1 && Point == 4){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 5:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;      
      }
      else if(Counter > 1 && Point == 5){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 6:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;
      }      
      else if(Counter > 1 && Point == 6){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 7:
      if(Counter == 1 && Point == 0){
      cout << "WINNER!!! You rolled a " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1 && Point >= 1) {
      cout << "SORRY!! You did not win ......:(PLEASE  AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 8:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;
      }
      else if(Counter > 1 && Point == 8){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
}
case 9:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;
      }
      else if(Counter > 1 && Point == 9){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;      
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 10:
      if(Counter == 1){
      cout << "Your Point is Set at " << SumOfDice <<" Please roll again" << endl;
      Point = SumOfDice;
break;      
      }
      else if(Counter > 1 && Point == 10){
      cout << "WINNER!!! You rolled your POINT of " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
case 11:
      if(Counter == 1){
      cout << "WINNER!!! You rolled a " << SumOfDice << " You Just won " << Bet <<" Dollars" << endl;
      TotalMoney = TotalMoney + Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;      
      }
      else{
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;
break;
      }
case 12:
      if(Counter == 1){
      cout << "SORRY!! You did not win......:( PLEASE TRY AGAIN!!" << endl;
      TotalMoney = TotalMoney - Bet;
      cout << "You Have $" << TotalMoney << ".00 Please Place your bet!!" << endl;
      cin >> Bet;
      Counter = 0;
      Point = 0;
break;
      }
      else if(Counter > 1){
      cout << "You did not roll your POINT!! PLEASE ROLL AGAIN!!!" << endl;

break;
}      
      return 0;


}    
      }
            }
             
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now