Question #33155

Write a C++ program which reads values for two floats and outputs their sum, product and quotient. Include a sensible input prompt and informative output.

Expert's answer

#include <iostream>


using namespace std;


int main(){
float a, b;
cout << "Input two numbers: ";
cin >> a >> b;


cout << "Sum is: " << a + b << endl;
cout << "Product is: " << a * b << endl;
if( b != 0 ) cout << "Quotient is: " << a / b << endl;
else cout << "Division by zero" << endl;


return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS