0% found this document useful (0 votes)
15 views3 pages

Arithmetic Computation

The document contains code for a C++ program that displays a menu allowing a user to choose between calculating the average, product, quotient or maximum of two numbers. The program uses functions to perform the calculations and returns the results to the user.

Uploaded by

Lord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Arithmetic Computation

The document contains code for a C++ program that displays a menu allowing a user to choose between calculating the average, product, quotient or maximum of two numbers. The program uses functions to perform the calculations and returns the results to the user.

Uploaded by

Lord
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//OBOH LORD

//9012531222
//MC(B) COMPUTER PROGRAMMING

#include <iostream>
using namespace std;

// Function prototypes
void displayMenu();
void average();
void multiplication();
void division();
void maximum();

int main()
{
int choice;
char confirm;

do {
displayMenu();

cout << "\nEnter your choice (1-5): ";


cin >> choice;

switch (choice) {
case 1:
average();
break;
case 2:
multiplication();
break;
case 3:
division();
break;
case 4:
maximum();
break;
case 5:
cout << "\nExiting program...\n";
return 0;
default:
cout << "\nInvalid choice. Please try again.\n";
}

cout << "\nDo you want to continue (Y/N)? ";


cin >> confirm;
} while (confirm == 'y' || confirm == 'Y');

cout << "\nExiting program...\n";


return 0;
}

void displayMenu()
{
cout << "\nMenu:\n";
cout << "1. Average\n";
cout << "2. Multiplication\n";
cout << "3. Division\n";
cout << "4. Maximum\n";
cout << "5. Exit\n";
}

void average()
{
float fnum, snum;
cout << "\nEnter the first number: ";
cin >> fnum;
cout << "Enter the second number: ";
cin >> snum;

float avg = (fnum + snum) / 2;


cout << "The average of " << fnum << " and " << snum << " is " << avg
<< endl;
}

void multiplication()
{
float fnum, snum;
cout << "\nEnter the first number: ";
cin >> fnum;
cout << "Enter the second number: ";
cin >> snum;

float product = fnum * snum;


cout << "The product of " << fnum << " and " << snum << " is " <<
product << endl;
}

void division()
{
float fnum, snum;
cout << "\nEnter the first number: ";
cin >> fnum;
cout << "Enter the second number: ";
cin >> snum;

if (snum == 0) {
cout << "Cannot divide by zero.\n";
return;
}

float quotient = fnum / snum;


cout << "The quotient of " << fnum << " and " << snum << " is " <<
quotient << endl;
}

void maximum()
{
float fnum, snum;
cout << "\nEnter the first number: ";
cin >> fnum;
cout << "Enter the second number: ";
cin >> snum;

float max;
if (fnum > snum) {
max = fnum;
} else {
max = snum;
}

cout << "The maximum of " << fnum << " and " << snum << " is " << max
<< endl;
}

You might also like