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

MRK - Spring 2024 - CS201 - 1 - BC230414368

The document describes a C++ program that acts as a basic menu-driven calculator. The program displays a menu with options for addition, subtraction, multiplication, division, and exit. It prompts the user for a choice and performs the selected arithmetic operation on numbers input by the user, displaying the result. This repeats until the user chooses the exit option.

Uploaded by

burhansahab5
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)
26 views3 pages

MRK - Spring 2024 - CS201 - 1 - BC230414368

The document describes a C++ program that acts as a basic menu-driven calculator. The program displays a menu with options for addition, subtraction, multiplication, division, and exit. It prompts the user for a choice and performs the selected arithmetic operation on numbers input by the user, displaying the result. This repeats until the user chooses the exit option.

Uploaded by

burhansahab5
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

Program

#include <iostream>

using namespace std;

int main() {

// Hard-code student id and name

string studentId = "YourStudentID";

string name = "YourName";

// Display student id and name

cout << "Student ID: " << studentId << endl;

cout << "Name: " << name << endl;

// Menu display and operations

int choice;

do {

// Display menu

cout << "\nMenu:\n";

cout << "1. Addition\n";

cout << "2. Subtraction\n";

cout << "3. Multiplication\n";

cout << "4. Division\n";

cout << "5. Exit\n";

cout << "Enter your choice: ";

cin >> choice;


// Perform operations based on user choice

switch (choice) {

case 1: { // Addition

int numAdd;

cout << "How many numbers do you want to add? ";

cin >> numAdd;

int sum = 0;

for (int i = 0; i < numAdd; i++) {

int num;

cout << "Enter number " << i + 1 << ": ";

cin >> num;

sum += num;

cout << "Result: " << sum << endl;

break;

case 2: { // Subtraction

int numSub;

cout << "How many numbers do you want to subtract? ";

cin >> numSub;

int result;

cout << "Enter number 1: ";

cin >> result;

for (int i = 1; i < numSub; i++) {

int num;

cout << "Enter number " << i + 1 << ": ";

cin >> num;

result -= num;

}
cout << "Result: " << result << endl;

break;

// Add cases for multiplication, division, and exit here

} while (choice != 5); // Continue until the user chooses to exit

return 0;

output of the program

The output of the program is a simple menu-based calculator that allows the user to perform
basic arithmetic operations like addition, subtraction, multiplication, and division. The program
displays the menu and prompts the user to enter their choice. Based on the selected operation,
the program asks for input (numbers to perform the operation on) and displays the result of the
operation. This process continues until the user chooses to exit the program.

You might also like