- GuestGuest

## program that asks the user to enter two numbers

on Tue Sep 07, 2010 7:03 am

/******************************************************

** Name:

** Filename: numbers.cpp

** Project #: Deitel & Deitel 1.23

** Project Description: Write a program that asks the user to enter

two numbers, obtains the two numbers from the user and prints

the sum,product,difference, and quotient of the two numbers.

** Output:

Sum of two numbers

Product of two numbers

Quotient of two numbers

Difference of two numbers

** Input:

Two whole numbers of the users choice

** Algorithm:

Explain function to be performed

Direct user to choose two whole numbers

Take the two numbers that are input and calculate

Sum

Product

Quotient

Difference between two numbers

Print sum

Print product

Print quotient

Print difference

******************************************************/

// Include files

#include <iostream> // used for cin, cout

#include <conio.h>

using namespace std;

// Global Type Declarations

// Function Prototypes

void instruct (void);

void pause ();

//Global Variables - should not be used without good reason.

int main ()

{

// Declaration section

double num1, num2, sum, product, quotient;

// Executable section

instruct ();

cout << "Enter first number: ";

cin >> num1;

cout << "Enter second number: ";

cin >> num2;

sum = num1 + num2;

product = num1 * num2;

quotient = num1 / num2;

cout << "\nThe sum of " << num1 << " and " << num2 << " is "

<< sum

<< "\nThe product of " << num1 << " multiplied by " << num2 << " is "

<< product

<< "\nThe quotient of " << num1 << " divided by " << num2 << " is "

<< quotient << endl;

cout << "\nThe difference of the two numbers is as follows: "

<< endl;

if ( num1 == num2 )

cout << num1 << " is equal to " << num2 << endl;

if ( num1 != num2 )

cout << num1 << " is not equal to " << num2 << endl;

if ( num1 < num2 )

cout << num1 << " is less than " << num2 << endl;

if ( num1 > num2 )

cout << num1 << " is greater than " << num2 << endl;

if ( num1 <= num2 )

cout << num1 << " is less than or equal to "

<< num2 << endl;

if ( num1 >= num2 )

cout << num1 << " is greater than or equal to "

<< num2 << endl;

pause ();

return 0;

}

void instruct (void)

{

// Declaration section

// Executable section

cout << "Choose two whole numbers to input below. The program will\n"

<< "then calculate the sum, the product, the difference, and the\n"

<< "quotient of the two numbers that have been input.\n "<< endl;

}

void pause ()

{

// Declaration section

// Executable section

cout << "\nPress any key to continue...";

getch();

cout << "\r";

cout << " ";

cout << "\r";

}

/*

Program Output

Choose two whole numbers to input below. The program will

then calculate the sum, the product, the difference, and the

quotient of the two numbers that have been input.

Enter first number: 6

Enter second number: 4

The sum of 6 and 4 is 10

The product of 6 multiplied by 4 is 24

The quotient of 6 divided by 4 is 1.5

The difference of the two numbers is as follows:

6 is not equal to 4

6 is greater than 4

6 is greater than or equal to 4

Press any key to continue...

*/

** Name:

** Filename: numbers.cpp

** Project #: Deitel & Deitel 1.23

** Project Description: Write a program that asks the user to enter

two numbers, obtains the two numbers from the user and prints

the sum,product,difference, and quotient of the two numbers.

** Output:

Sum of two numbers

Product of two numbers

Quotient of two numbers

Difference of two numbers

** Input:

Two whole numbers of the users choice

** Algorithm:

Explain function to be performed

Direct user to choose two whole numbers

Take the two numbers that are input and calculate

Sum

Product

Quotient

Difference between two numbers

Print sum

Print product

Print quotient

Print difference

******************************************************/

// Include files

#include <iostream> // used for cin, cout

#include <conio.h>

using namespace std;

// Global Type Declarations

// Function Prototypes

void instruct (void);

void pause ();

//Global Variables - should not be used without good reason.

int main ()

{

// Declaration section

double num1, num2, sum, product, quotient;

// Executable section

instruct ();

cout << "Enter first number: ";

cin >> num1;

cout << "Enter second number: ";

cin >> num2;

sum = num1 + num2;

product = num1 * num2;

quotient = num1 / num2;

cout << "\nThe sum of " << num1 << " and " << num2 << " is "

<< sum

<< "\nThe product of " << num1 << " multiplied by " << num2 << " is "

<< product

<< "\nThe quotient of " << num1 << " divided by " << num2 << " is "

<< quotient << endl;

cout << "\nThe difference of the two numbers is as follows: "

<< endl;

if ( num1 == num2 )

cout << num1 << " is equal to " << num2 << endl;

if ( num1 != num2 )

cout << num1 << " is not equal to " << num2 << endl;

if ( num1 < num2 )

cout << num1 << " is less than " << num2 << endl;

if ( num1 > num2 )

cout << num1 << " is greater than " << num2 << endl;

if ( num1 <= num2 )

cout << num1 << " is less than or equal to "

<< num2 << endl;

if ( num1 >= num2 )

cout << num1 << " is greater than or equal to "

<< num2 << endl;

pause ();

return 0;

}

void instruct (void)

{

// Declaration section

// Executable section

cout << "Choose two whole numbers to input below. The program will\n"

<< "then calculate the sum, the product, the difference, and the\n"

<< "quotient of the two numbers that have been input.\n "<< endl;

}

void pause ()

{

// Declaration section

// Executable section

cout << "\nPress any key to continue...";

getch();

cout << "\r";

cout << " ";

cout << "\r";

}

/*

Program Output

Choose two whole numbers to input below. The program will

then calculate the sum, the product, the difference, and the

quotient of the two numbers that have been input.

Enter first number: 6

Enter second number: 4

The sum of 6 and 4 is 10

The product of 6 multiplied by 4 is 24

The quotient of 6 divided by 4 is 1.5

The difference of the two numbers is as follows:

6 is not equal to 4

6 is greater than 4

6 is greater than or equal to 4

Press any key to continue...

*/

**Permissions in this forum:**

**cannot**reply to topics in this forum

arvie21arvie21arvie21radaxradaxradaxradaxradaxradaxradaxradaxradaxradaxmherlcanrickzmanansalarickzmanansalarickzmanansalarickzmanansalarickzmanansalarickzmanansalarickzmanansalarickzmanansalarickzmanansalarickzmanansalarickzmanansalarickzmanansalameowchimherlcanBlexBlexarvie21arvie21BlexBlexarvie21arvie21bonnkeivyradaxviraxzradaxINKHRIPTORjcodeejcodeeradaxradaxBlexradaxradaxradaxradaxradaxmeowchimeowchimeowchimeowchiradaxmeowchiradax