For my homework assignment, I'm supposed to get five numbers from a user and print the highest one using a loop. I'm not sure what to do. Any suggestions?
sfurlow2
0
Light Poster
Recommended Answers
Jump to Postsuggestion
int main() { // put your code here return 0; }
Ok, so lets assume you know how to do the above. You need a for/next loop that counts from 0 to 5, display a prompt, get input using cin, then keep track of the highest …
Jump to Postby having a variable ( i.e. int highest; ) and using an if statement after the cin to check if it is higher or lower than the one they just input, then keep the higher of the two stored there....
Jump to PostAll you did on line 12 is display the value of highest. You never set it to anything. Initialize the value of highest to 0 before the loop starts, then when the if condition is true set highest = x
you also need to incude <iostream> at the top of …
Jump to Postok, should more look something like this:
#include <iostream> //needed for cout and cin using namespace std; //also needed... int main(){ int counter = 0; int highest = 0; int input = 0; for(counter = 1; counter <= 5; counter++){ //input the number from the user. cin …
All 13 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
sfurlow2
0
Light Poster
evilsilver
0
Junior Poster in Training
sfurlow2
0
Light Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
evilsilver
0
Junior Poster in Training
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
evilsilver
0
Junior Poster in Training
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
sfurlow2
0
Light Poster
sfurlow2
0
Light Poster
VernonDozier
2,218
Posting Expert
Featured Poster
sfurlow2
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.