| | |
Print highest
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
suggestion
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 number entered (you need another variable to do that).
C++ Syntax (Toggle Plain Text)
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 number entered (you need another variable to do that).
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Feb 2008
Posts: 26
Reputation:
Solved Threads: 0
I'm still having problems with this. So far, I have this:
I'm still not sure what to do.
C++ Syntax (Toggle Plain Text)
int main() { int x; int highest; int counter; for (counter=1;counter<=5;counter++) { cin >> x; if (highest > x); cout << highest << endl; } cin.ignore(INT_MAX); getchar(); return 0; }
Last edited by Ancient Dragon; Feb 26th, 2008 at 6:57 pm. Reason: add code tags
All 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 your program and add the
you also need to incude <iostream> at the top of your program and add the
using namespace std; statement or add [icode]std::[/b] before each cin statement. I use the using statement because it doesn't require as much typing, but many programmers don't like that. Unless your teacher says otherwise its your call which way to do it. Last edited by Ancient Dragon; Feb 26th, 2008 at 7:02 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
ok, should more look something like this:
c++ Syntax (Toggle Plain Text)
#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 >> input; //if the number they input is higher than what we already have, //store that number instead if(input > highest) highest = input; }//end the fore loop cout << highest << endl; return 0; }
Last edited by evilsilver; Feb 26th, 2008 at 8:01 pm.
>>ok, should more look something like this:
Did you compile and run that if there are no compile errors or warnings? That's the easiest way to find out if your code is correct or not.
Did you compile and run that if there are no compile errors or warnings? That's the easiest way to find out if your code is correct or not.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
•
•
(ummm.... i wasn't the one having the problem with the code, i know for a fact that the code i posted works... i was posting it so sfurlow2 could see how to do it, else i wouldn't have commented it i would just have put a code snipet for all to see and copy... sorry just sayin....)
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Echoing the highest of ten inputed numbers. (Shell Scripting)
- array help plz! (C++)
- Program help please!!! (C++)
- Print the parallel array index with the largest value? (C++)
- March Madness Program Help (Visual Basic 4 / 5 / 6)
- helllp with loops (C++)
Other Threads in the C++ Forum
- Previous Thread: c++ looping program
- Next Thread: Class Template used for stack
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






