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 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top