C++. Write a program that inputs two numbers and determines which of the two num
ID: 3823730 • Letter: C
Question
C++. Write a program that inputs two numbers and determines which of the two numbers is the smallest. If the numbers are equal, display a message that they are equal. Using the pseudocode below, write the code that will meet the requirements: Display description of program Prompt the user for the first number Prompt the user for the second number If first number equals second number Display the two numbers are equal Else If first number is greater than second number Assign second number to smallest Else Assign first number to smallest End-If Display smallest number End-If
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int first, second;
cout<<"Enter the first number: ";
cin >> first;
cout<<"Enter the second number: ";
cin >> second;
if(first < second){
cout<<"Small value is "<<first<<endl;
}
else if(second < first){
cout<<"Small value is "<<second<<endl;
}
else{
cout<<"Both values are equals"<<endl;
}
return 0;
}
Outpu:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the first number: 4
Enter the second number: 5
Small value is 4
sh-4.2$ main
Enter the first number: 4
Enter the second number: 4
Both values are equals
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.