MHB Continuously Bid with While Loop - Stop at 'n' | Sample Program

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Loop
Click For Summary
The discussion focuses on creating a loop in a C++ program that continues to bid until the user inputs 'n'. The sample program initializes a character variable to track user input and an integer for the bid amount. The user is prompted to continue bidding, and the loop should run as long as the input is not 'n'. A participant points out that the original attempts to check the condition were incorrect because they were mistakenly checking the wrong variable. The correct approach is to evaluate the 'keepGoing' variable, which stores the user's response, ensuring the loop continues until 'n' is entered.
ineedhelpnow
Messages
649
Reaction score
0
Write an expression that continues to bid until the user enters 'n'.

Sample program:
Code:
#include <iostream>
using namespace std;

int main() {
   char keepGoing = '-';
   int nextBid = 0;

   srand(5);
   while (<STUDENT CODE>) {
      nextBid = nextBid + (rand()%10 + 1);
      cout << "I'll bid $" << nextBid << "!" << endl;
      cout << "Continue bidding? ";
      cin >> keepGoing;
   }
   cout << endl;

   return 0;
}

help me (Headbang) i tried nextBid<'n' nextBid != 'n' !(nextBid='n'). nothing works.
 
Technology news on Phys.org
You are checking the wrong variable...it is [m]keepGoing[/m] that stores the user input...:D
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

Replies
12
Views
3K
  • · Replies 66 ·
3
Replies
66
Views
5K
Replies
10
Views
2K
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 39 ·
2
Replies
39
Views
4K
Replies
3
Views
1K