C++ Language
Branching
Determine if numbers are equivalent.
a) Request two floating point numbers from the console.
b) If the numbers are equivalent, output that they are
equivalent.
c) If the numbers are not equivalent, output the larger number.
Example output 1 (input is bold and italicized):
Enter two numbers: 10.2 8.5
10.2 is the larger number.
Example output 2 (input is bold and italicized):
Enter two numbers: 5 5
5 is equivalent to 5.
#include<iostream> using namespace std; int main() { float x, y; cout<<"Enter two numbers: "; cin>>x>>y; if(x==y){ cout<<x<<" is equivalent to "<<y<<"."<<endl; } else if(x>y){ cout<<x<<" is the larger number."<<endl; } else{ cout<<y<<" is the larger number."<<endl; } return 0; }
Get Answers For Free
Most questions answered within 1 hours.