| | |
a little help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2004
Posts: 18
Reputation:
Solved Threads: 0
I've written the program out but I'm not sure on how I can get the largest and smallest # to display.. can anyone help? thanks.
Write a program with a loop that lets the user enter a series of integers. The user should enter -99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest numbers entered.
#include <iostream>
using namespace std;
int main()
{
int number = 0;
cout << "This program will let you enter number after\n";
cout << "number. Enter 99 when you want to quit the ";
cout << "program.\n";
while (number !=99)
cin >> number;
cout << "Done\n";
return 0;
}
Write a program with a loop that lets the user enter a series of integers. The user should enter -99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest numbers entered.
#include <iostream>
using namespace std;
int main()
{
int number = 0;
cout << "This program will let you enter number after\n";
cout << "number. Enter 99 when you want to quit the ";
cout << "program.\n";
while (number !=99)
cin >> number;
cout << "Done\n";
return 0;
}
•
•
Join Date: Aug 2004
Posts: 140
Reputation:
Solved Threads: 1
I think this would work:
#include <iostream> using namespace std; int main() { ///////////////////////////////Creating variables///////////////////////////////////// int number = 0; int min, max; ///////////////////////////////Blah!Blah!Blah!Blah!/////////////////////////////////// cout << "This program will let you enter number after\n"; cout << "number. Enter 99 when you want to quit the "; cout << "loop.\n"; ///////////////////////For initialising values of min and max//////////////////////// cin>>number; if(number==99) return(0); //if the number is 99 the program will quit min = max = number; //initialize the values of min and max to compare with later inputs ///////////////////////////Loop to get the numbers///////////////////////////////// while(number!=99) //loop { cin>>number; /////////////////////////////Evaluating the numbers///////////////////////////////// if(number ==99) break; //break the loop or else max will become 99 if this line is not there else if(number>max) max = number; //if the no. is greater than max then it becomes the max else if(number<min) min = number; // if the no. is smaller than min then it becomes min } //end of loop ////////////////////Printing the smallest and biggest numbers///////////////////// cout<<"The smallest number is: "<<min<<endl; //displays smallest no. cout<<"The biggest number is: "<<max<<endl; //displays biggest no. return 0; }
>cout << "loop.\n"; does this play any role or its just an output -> "n"
I assume you mean \n. It's an escape character that tells cout to print a newline.
>Why did we have to equal the min and max to number...? Which is 0?
min and max denote the smallest and largest value encountered, respectively. Because at this point the only value encountered was number, both min and max must be that value.
>Are max and min are reserved word for C++.
Yes and no. The rules are a bit tricky, but in this case there's no problem.
I assume you mean \n. It's an escape character that tells cout to print a newline.
>Why did we have to equal the min and max to number...? Which is 0?
min and max denote the smallest and largest value encountered, respectively. Because at this point the only value encountered was number, both min and max must be that value.
>Are max and min are reserved word for C++.
Yes and no. The rules are a bit tricky, but in this case there's no problem.
I'm here to prove you wrong.
![]() |
Other Threads in the C++ Forum
- Previous Thread: C++ development on Linux/Unix?
- Next Thread: printing a linked list
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






