Include
Include
do {
cout << "Hello " << "Eshah " << ",StudentId=" << "BC230410520" <<
",Welcomme to the main menu" << endl;
cout << "1. Addition" << endl;
cout << "2. Subtraction" << endl;
cout << "3. Multiplication" << endl;
cout << "4. Division" << endl;
cout << "5. Exist" << endl;
cout << "Enter your choice: ";
cin >> choice;
int num;
float result;
switch(choice) {
case 1 : {
cout << "How many numbers do you want to add? ";
cin >> num;
result = 0;
for(int i = 0; i < num; ++i) {
float temp;
cout << "Enter numbers " << i + 1 << ": ";
cin >> temp;
result += temp;
}
cout << "Result of addition: " << result << endl;
break;
}
case 2 : {
cout << "How many numbers do you want to subtract? ";
cin >> num;
cout << "Enter number 1: ";
cin >> result;
for(int i = 0; i < num; ++i) {
float temp;
cout << "Enter number " << i + 1 << ": ";
cin >> temp;
result -= temp;
}
cout << "Result of subtraction: " << result << endl;
break;
}
case 3 : {
cout << "How many numbers do to want to multiply? ";
cin >> num;
result = 1;
for(int i = 0; i < num; ++i) {
float temp;
cout << "Enter number " << i + 1 << ": ";
cin >> temp;
result *= temp;
}
cout << "Result of multiplication: " << result << endl;
break;
}
case 4 : {
cout << "How many numbers do tou want to divide? ";
cin >> num;
cout << "Enter number 1: ";
cin >> result;
for(int i = 0; i < num; ++i) {
float temp;
cout << "Enter number " << i + 1 << ": ";
cin >> temp;
if(temp == 0) {
cout << "Error! Division by zero is impossible. Please
divide it by a non-zero divisor. " << endl;
break;
}
result /= temp;
}
cout << "Result of division: " << result <<endl;
break;
}
case 5 : {
cout << "Exist program. " << endl;
break;
}
default: {
cout << "Invalid choice! Please enter a number between 1 and 5.
" << endl;
break;
}
}
if(choice != 5) {
cout << "Do you want to continue (y/n)? ";
cin >> choice;
}
}while(choice == 'y' || choice == 'Y');
return 0;
}