0% found this document useful (0 votes)
52 views

Using Namespace Int: #Include #Include

This C++ program uses nested switch statements to allow a user to select an arithmetic operation (addition, subtraction, multiplication, or division) and number of integers (2 to 5) to perform the operation on. Based on the user's selection, it will prompt for the appropriate number of integer inputs and display the result of performing the selected operation.

Uploaded by

superbawang321
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)
52 views

Using Namespace Int: #Include #Include

This C++ program uses nested switch statements to allow a user to select an arithmetic operation (addition, subtraction, multiplication, or division) and number of integers (2 to 5) to perform the operation on. Based on the user's selection, it will prompt for the appropriate number of integer inputs and display the result of performing the selected operation.

Uploaded by

superbawang321
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/ 4

// nestedswitch.cpp : Defines the entry point for the console application.

//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
//Initialization
int d;
float num1 = 0.0;
float num2 = 0.0;
float num3 = 0.0;
float num4 = 0.0;
float num5 = 0.0;
float sum = 0.0;
float dif = 0.0;
float pro = 0.0;
float quo = 0.0;
char m;
//Body
cout << "What mathematical operation would you like to use?\n";
cout << "A - Addition\n";
cout << "B - Subtraction\n";
cout << "C - Multiplication\n";
cout << "D - Division\n";
cout << "Answer : "; cin >> m;
cout << "\nHow many integers would you like to use? (2 to 5) : "; cin >> d;
switch (m)
{
case 'A':
switch (d) {
case 2: cout << "Enter the first integer : ";
cin >> num1;
cout << "Enter the second integer : ";
cin >> num2;
sum = num1 + num2;
cout << "\nThe sum of the two integers is : " << sum << "\n" <<
endl;
break;
case 3: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
sum = num1 + num2 + num3;
cout << "The sum of the three integers is : " << sum << "\n" <<
endl;
break;
case 4: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
cout << "Enter the fourth integer :";
cin >> num4;
sum = num1 + num2 + num3 + num4;
cout << "The sum of the four integers is : " << sum << "\n" << endl;
break;
case 5: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
cout << "Enter the fourth integer :";
cin >> num4;
cout << "Enter the fifth integer :";
cin >> num5;
sum = num1 + num2 + num3 + num4 + num5;
cout << "The sum of the five integers is : " << sum << "\n" << endl;
break;
default: cout << "Enter only value from 2 to 5.\n";
}

break;
case 'B':
switch (d) {
case 2: cout << "Enter the first integer : ";
cin >> num1;
cout << "Enter the second integer : ";
cin >> num2;
dif = num1 - num2;
cout << "\nThe difference of the two integers is : " << dif << "\n"
<< endl;
break;
case 3: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
dif = num1 - num2 - num3;
cout << "The difference of the three integers is : " << dif << "\n"
<< endl;
break;
case 4: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
cout << "Enter the fourth integer :";
cin >> num4;
dif = num1 - num2 - num3 - num4;
cout << "The difference of the four integers is : " << dif << "\n"
<< endl;
break;
case 5: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
cout << "Enter the fourth integer :";
cin >> num4;
cout << "Enter the fifth integer :";
cin >> num5;
dif = num1 - num2 - num3 - num4 - num5;
cout << "The difference of the five integers is : " << dif << "\n"
<< endl;
break;
default: cout << "Enter only value from 2 to 5.\n";
}

break;
case 'C':
switch (d) {
case 2: cout << "Enter the first integer : ";
cin >> num1;
cout << "Enter the second integer : ";
cin >> num2;
pro = num1*num2;
cout << "\nThe product of the two integers is : " << pro << "\n" <<
endl;
break;
case 3: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
pro = num1*num2*num3;
cout << "The product of the three integers is : " << pro << "\n" <<
endl;
break;
case 4: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
cout << "Enter the fourth integer :";
cin >> num4;
pro = num1*num2*num3*num4;
cout << "The product of the four integers is : " << pro << "\n" <<
endl;
break;
case 5: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
cout << "Enter the fourth integer :";
cin >> num4;
cout << "Enter the fifth integer :";
cin >> num5;
pro = num1*num2*num3*num4*num5;
cout << "The product of the five integers is : " << pro << "\n" <<
endl;
break;
default: cout << "Enter only value from 2 to 5.\n";
}

break;
case 'D':
switch (d) {
case 2: cout << "Enter the first integer : ";
cin >> num1;
cout << "Enter the second integer : ";
cin >> num2;
quo = num1 / num2;
cout << "\nThe quotient of the two integers is : " << quo << "\n" <<
endl;
break;
case 3: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
quo = num1 / num2 / num3;
cout << "The quotient of the three integers is : " << quo << "\n" <<
endl;
break;
case 4: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
cout << "Enter the fourth integer :";
cin >> num4;
quo = num1 / num2 / num3 / num4;
cout << "The quotient of the four integers is : " << quo << "\n" <<
endl;
break;
case 5: cout << "Enter the first integer :";
cin >> num1;
cout << "Enter the second integer :";
cin >> num2;
cout << "Enter the third integer :";
cin >> num3;
cout << "Enter the fourth integer :";
cin >> num4;
cout << "Enter the fifth integer :";
cin >> num5;
quo = num1 / num2 / num3 / num4 / num5;
cout << "The quotient of the five integers is : " << quo << "\n" <<
endl;
break;
default: cout << "Enter only value from 2 to 5.\n";
}
}
cin.clear(); cin.ignore(); cin.get();
}

You might also like