- 3
How can I make this?
Create 5 numbers and will output the highest and lowest number inputted
6 Answers
+ 1
And your try?
Please refer:
https://www.sololearn.com/discuss/1316935/?ref=app
0
#include <iostream>
using namespace std;
int main() {
int a,b;
cout<<"enter the number : ";
cin>>a>>b;
if (a<b)
cout<<"the "<<b<<" is highest number"<<endl;
else if (a>b)
cout<<"the "<<a<<" is lowest number"<<endl;
else
cout<<"the "<<a<<b<<" equal number";
return 0;
}
0
Your mistake in your code is here
else if (a>b)
cout<<"the "<<b<<" is lowest number"<<endl;
But if you want to compare 5 numbers, then you will need to adapt your code to suit.
0
Adaption suggestions
Create a for loop which will generate 5 integer inputs and assign them to an srray
Create 2 variables, one called min & one called max.
assign the values of min and max to the first item in your list.
Now iterate through your list using your comparison operators.
if the list item is greater than the max value, re-assign max to the current item
if the list item is smaller than the min value, then re-assign min to the current item
By the end of the iteration, min & max will contain the smallest & largest number of the array
print results



