- 3

How can I make this?

Create 5 numbers and will output the highest and lowest number inputted

21st Dec 2021, 1:48 AM
Jhenald Tampis
Jhenald Tampis - avatar
6 Answers
21st Dec 2021, 2:32 AM
NEZ
NEZ - avatar
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; }
21st Dec 2021, 3:19 AM
M.M.F Atheeqa
M.M.F Atheeqa - avatar
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.
21st Dec 2021, 4:01 AM
Rik Wittkopp
Rik Wittkopp - avatar
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
21st Dec 2021, 4:07 AM
Rik Wittkopp
Rik Wittkopp - avatar