Solved

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

Posted on 2004-10-11
4
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

627 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