Question

Can someone help me make the output of this code more spaced out? #include<iostream> #include<cstdlib> using...

Can someone help me make the output of this code more spaced out?

#include<iostream>
#include<cstdlib>

using namespace std;

int main()
{
   int amount=1000,guess,answer,bet,count=0,win=0;
   float per;
   char ch;
   cout<<"Welcome to the high-low betting game.\nYou have $1000 to begin the game.\nValid guesses are numbers between 1 and 100.\n";
   do
   {
       cout<<"Please enter a bet:\n";
       cin>>bet;
       answer=rand()%100;
       for (int i=0;i<6;i++)
       {
           cout<<"Guess "<<i+1<<":";
           cin>>guess;
           if (guess<1||guess>100)
           cout<<"That isn't a valid bet!\n";
           else if (guess==answer)
           {
               win++;
               count++;
               cout<<"Correct!\nYou just won $100";
               amount=amount+100;
               per=win/count*100;
               cout<<"\nYou have $"<<amount<<"\nYou have won "<<per<<"% of the games you played";
               cout<<"\nPlay Again?";
               cin>>ch;
               break;
           }
           else if (guess<answer)
           {
               cout<<"Too low...\n";
           }
           else if (guess>answer)
           cout<<"Too high...\n";
          
           if (i==5)
           {
               count++;
               if (win<count)
               {
                   amount=amount-bet;
                   per=win/count*100;
                   cout<<"Sorry... the correct answer was "<<answer<<"\nYou lost $"<<bet<<"\nYou have $"<<amount;
                   cout<<"\nYou have won "<<per<<"% of the games you played";
                   cout<<"\nPlay Again?";
                   cin>>ch;
               }
           }  
       }
   }
   while(ch=='y'||ch=='Y');
   cout<<"\nThanks for playing.";
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ code:

#include<bits/stdc++.h>

using namespace std;

//main function

int main(int argc, char const *argv[])

{

    // Initialize all variables

   int amount=1000,guess,answer,bet,count=0,win=0;

   float per;

   char ch;

   // Show the menu

   cout<<"\n\n";

   cout<<"Welcome to the high-low betting game.\nYou have $1000 to begin the game.\n\nValid guesses are numbers between 1 and 100.\n\n";

   do

   {   // Ask for input

       cout<<"Please enter a bet:\n";

       cin>>bet;

       // Generate random number

       answer=rand()%100;

       for (int i=0;i<6;i++)

       {

           cout<<"\n";

           cout<<"Guess "<<i+1<<": ";

           cin>>guess;

           if (guess<1||guess>100)

           // for invalid input

           cout<<"That isn't a valid bet!\n";

           // if guess number equal to answer

           else if (guess==answer)

           {

               win++;

               count++;

               cout<<"\n";

               // display the win coins menu

               cout<<"Correct!\n\nYou just won $100";

               amount=amount+100;

               per=win/count*100;

               cout<<"\nYou have $"<<amount<<"\nYou have won "<<per<<"% of the games you played";

               cout<<"\n";

               cout<<"\nPlay Again?";

               cin>>ch;

               break;

           }

           // guess number is less than answer

           else if (guess<answer)

           {

               cout<<"Too low...\n";

           }

           // guess number is greater than answer

           else if (guess>answer)

           cout<<"Too high...\n";

          

           if (i==5)

           {

               count++;

               if (win<count)

               {

                   amount=amount-bet;

                   per=win/count*100;

                   cout<<"\n";

                    // display the loss coins menu

                   cout<<"Sorry... the correct answer was "<<answer<<"\n\nYou lost $"<<bet<<"\nYou have $"<<amount;

                   cout<<"\nYou have won "<<per<<"% of the games you played";

                   cout<<"\n";

                   cout<<"\nPlay Again?";

                   cin>>ch;

               }

           }  

       }

   }

   // ask choice for again playing the game

   while(ch=='y'||ch=='Y');

   cout<<"\nThanks for playing.";

      cout<<"\n\n";

  return 0;   

}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Can someone help me make the output of this code more spaced out? #include<iostream> #include<cstdlib> using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0));...

    #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0)); int number, guess, response, reply; int score = 0 number = rand() % 100 + 1; do { do { cout << "Enter your guess "; cin >> guess; score++; if (guess < number) cout << guess << " is too low! Enter a higher number. "; else if (guess > number) cout << guess << " is too high! Enter a lower number....

  • Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer...

    Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer to catch the random variable value of two dicerolls at one time . //these global variable with static variable win use to operate the working of code . //static win, account because two times input given by user to add the diceroll with win number and //account (means balance of user) . static int account = 100; static int win = 0; int bet...

  • Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The...

    Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The game requires the user to guess a secret word. The game does not end until the user guesses the word. After they win the game, they are prompted to choose to play again. The secret word that user must guess is "valentine". It is a case-sensitive analysis With each guess... If the guess does not have an equal number of characters, tell the user...

  •    moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring>...

       moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...

  • #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sstream> using namespace...

    #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sstream> using namespace std; void DisplayMenu() {    cout << "1. E games\n";    cout << "2. T games\n";    cout << "3. M games\n";    cout << "4. Total Games\n";    cout << "5. Exit\n"; } double total(double egames, double tgames, double mgames) {    int totalgames = egames + tgames + mgames;    cout << "There are " << totalgames << " games\n";    return...

  • How to convert C++ code to C #include<iostream> #include <stdlib.h> using namespace std; void multiplication() {...

    How to convert C++ code to C #include<iostream> #include <stdlib.h> using namespace std; void multiplication() { int num1; int c, num2, ans; cout<<"Enter difficulty level(1/2)\n"; cin>>c; if(c==1) { num1= rand() % 10; num2= rand() % 10; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans while(ans!=(num1*num2)) { if(ans!=(num1*num2)) { cout<< "No. Please try again.\n"; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans; } } } else if(c==2) { num1= rand() % 10+90; num2= rand() % 10+90; cout<<"what is"<<num1 <<"*"<<num2<<"?\n" ; cin>>ans; while(ans!=(num1*num2)) { if(ans!=(num1*num2)) { cout<< "No....

  • Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN...

    Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() {    int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false;    srand(seed); // call the getRandom function below       tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...

  • The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[...

    The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[SIZE];    int player, choice, win, count;    char mark;    count = 0; // number of boxes marked till now    initBoard(board);       // start the game    player = 1; // default player    mark = 'X'; // default mark    do {        displayBoard(board);        cout << "Player " << player << "(" << mark...

  • can someone help me fix my jeopardy game #include<iostream> #include<stdlib.h> using namespace std; int rollDie() {...

    can someone help me fix my jeopardy game #include<iostream> #include<stdlib.h> using namespace std; int rollDie() { return (rand() % 6+1); } void askYoNs(){ cout<<"Do you want to roll a dice (Y/N)?:"<<endl; } void printScores(int turnTotal,int humanTotal,int compTotal){ int player; int human; if(player==human){ cout<<"Your turn total is "<<turnTotal<<endl; } else{ cout<<"computer turn total is "<<turnTotal<<endl; } cout<<"computer: "<<compTotal<<endl; cout<<"human: "<<humanTotal<<endl; cout<<endl; } int human; int changePlayer(int player){ if(player==human) return 1; return human; } int process(int& turnTotal,int roll,int curr_player,int& humanTotal,int& computerTotal){ if(roll==2...

  • Can anyone help me to make this program work in C language, this is a blackjack...

    Can anyone help me to make this program work in C language, this is a blackjack game #include #include #include void deal(int, int&) void deal(int, int&, int&) int getbet(int); int main() {    int totdealer, totplayer;    int money, bet, aces;    char yesno = 'Y';    _Bool again;    srand(time(0));    printf("How much money do you have? ");    scanf("%d" , money);    while (money>0 && toupper(yesno) == 'Y')    {        bet = getbet(money);        totdealer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT