A program prompts a user to enter two numbers, obtains the two numbers from the user, calculates and prints the sum, product, difference, and quotient of the two numbers.
1. Using Microsoft Word, Devise an Algorithm and Flowchart for the problem
C++ code:
#include<iostream>
#include<string>
using namespace std;
//The start point of the program
int main (){
float number1;
float number2;
//enter two numbers, obtains the two numbers from the user
cout<<"Enter the number 1: ";
cin>>number1;
cout<<"Enter the number 2: ";
cin>>number2;
// calculates and prints the sum, product, difference, and quotient of the two numbers.
float sum=number1+number2;
float product=number1*number2;
float difference=number1-number2;
float quotient=number1/number2;
cout<<"\nSum: "<<sum<<"\n";
cout<<"Product: "<<product<<"\n";
cout<<"Difference: "<<difference<<"\n";
cout<<"Quotient: "<<quotient<<"\n\n\n";
system("pause");
return 0;
}
Algorithm:
Start
Get number 1 from the user
Get number 2 from the user
Calculate sum=number1+number2;
Calculate product=number1*number2;
Calculate difference=number1-number2;
Calculate quotient=number1/number2;
Display sum
Display product
Display difference
Display quotient
Stop
Flowchart
Comments
Leave a comment