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

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Loop
AI Thread 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
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top