Concept explainers
I am not sure entirely How to store max value. These are my instructions:
"The variable userNumber should be used for storing the input the user gives you. The variable maxVal keeps track of the largest integer found so far.
In the loop, prompt and store the user's number. Then check, if userNumber is positive and userNumber is greater than maxVal. If it is, then update maxVal to equal userNumber. Repeat this process until userNumber is equal to the SENTINEL variable."
This is what I have thus far:
#include <iostream>
using namespace std;
int main()
{
// variables
int maxVal = 0, userNumber = 0;
const int SENTINEL = -1;
// TODO: create a `while` loop version of finding the maximum number
cout << "Enter a number: ";
cin >> userNumber;
while (userNumber != SENTINEL)
{
userNumber = ++maxVal;
cout << userNumber << endl;
}
// display results
cout << "\nMaximum number entered: " << maxVal << endl;
// terminate
return 0;
}
What am I missing?
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 3 images
- Need help on this question and can you explain how as well?arrow_forwardAgain, modify the while loop to utilize tolower() or toupper(). Create two more functions (options #3 and #4 in your menu) by taking the to_kilograms() and to_pounds() functions and modifying them to use reference variables instead of normal pass by value variables. Name them: to_kilograms_ref() to_pounds_ref() Create another two functions (options #5 and #6 in your menu) by taking the to_kilograms() and to_pounds() functions and modifying them to use pointers instead of normal pass by value variables. Name them: to_kilograms_ptr() to_pounds_ptr() Your new Menu should look like this, which includes what type of variables are being used: MENU 1. Kilograms to Pounds (pass by value) 2. Pounds to Kilograms (pass by value) 3. Kilograms to Pounds (pass by reference) 4. Pounds to Kilograms (pass by reference) 5. Kilograms to Pounds (using pointers) 6. Pounds to Kilograms (using pointers) Example: #include <iostream> #include <cmath>…arrow_forwardplease don't change variable namesarrow_forward
- Valid letters in this order only, P, S, W, M, A, H and need break word to break the iteration, valid input is END. If user enters wrong invalid input or nothing, error alert message should come up and ask user to re enter. Process should iterate until valid input entered.arrow_forwardIn this lab, you write a while loop that uses a sentinel value to control a loop in a Python program. You also write the statements that make up the body of the loop. The source code file already contains the necessary assignment and output statements. Each theater patron enters a value from 0 to 4 indicating the number of stars that the patron awards to the Guide’s featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. At the end of the program, you should display the average star rating for the movie.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education