This program works if the numbers are different, but not if they are the same. F
ID: 3634464 • Letter: T
Question
This program works if the numbers are different, but not if they are the same. Fix this.Next, the company wants the user to be able to input three numbers and put them in order.
Make the modification
#include <iostream.h>
Void main ()
{
Int i;
Int j;
Cout << “Enter the first integer: “<<endl;
Cin>> i;
Cout<< “Enter the second integer: “<<endl;
Cin>>j;
If (i == j)
Cout<< “The numbers are equal.”<<endl;
If (i < j)
Cout<< i << “ is less than “<<endl;
Else
Cout<< j <<” is less than “<<endl;
}
Explanation / Answer
Please Rate: Thanks
#include<iostream.h>
//main function
void main()
{
//Define 3 integr numbers
int a;
int b;
int c;
//read a number into a
cout<<" Enter first number ";
cin>>a;
//read a number into b
cout<<"Enter second number ";
cin>>b;
//read a number into c
cout<<"Enter third number ";
cin>>c;
if(a<=b && a<=c){ // a is smallest
if(b<=c)
cout<<a<<" "<<b<<" "<<c; // a<=b<=c
else
cout<<a<<" "<<c<<" "<<b; // a<=c<=b
}
else if(b<=a && b<=c){ // b is smallest
if(a<=c)
cout<<b<<" "<<a<<" "<<c; //b<=a<=c
else
cout<<b<<" "<<c<<" "<<a; //b<=c<=a
}
else // c is smallest
if(a<=b)
cout<<c<<" "<<a<<" "<<b; //c<=a<=b
else
cout<<c<<" "<<b<<" "<<a; //c<=b<=a
}
-------------------------------------------------------
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.