Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-11
4
Medium Priority
?
203 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

972 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