0% found this document useful (0 votes)
5 views2 pages

Math Counting Tool Program in C++

The document is a C++ program that implements a simple math counting tool with options for addition, subtraction, multiplication, and division. It allows users to perform calculations and count up to a specified limit, while handling division by zero errors. The program features a menu-driven interface for user interaction and continues until the user chooses to exit.

Uploaded by

Dimas Aldytama
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)
5 views2 pages

Math Counting Tool Program in C++

The document is a C++ program that implements a simple math counting tool with options for addition, subtraction, multiplication, and division. It allows users to perform calculations and count up to a specified limit, while handling division by zero errors. The program features a menu-driven interface for user interaction and continues until the user chooses to exit.

Uploaded by

Dimas Aldytama
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

#include <iostream> std::cout << "Result: " << a * b << std::endl;

}
void displayMenu() {
std::cout << "Math Counting Tool" << std::endl; void division() {
std::cout << "1. Count Up" << std::endl; double a, b;
std::cout << "2. Addition" << std::endl; std::cout << "Enter two numbers to divide (numerator and
denominator): ";
std::cout << "3. Subtraction" << std::endl;
std::cin >> a >> b;
std::cout << "4. Multiplication" << std::endl;
if (b != 0) {
std::cout << "5. Division" << std::endl;
std::cout << "Result: " << a / b << std::endl;
std::cout << "6. Exit" << std::endl;
} else {
std::cout << "Choose an option: ";
std::cout << "Error: Division by zero!" << std::endl;
}
}
}
void countUp(int limit) {
std::cout << "Counting up to " << limit << ":" << std::endl;
int main() {
for (int i = 1; i <= limit; ++i) {
int choice;
std::cout << i << " ";
do {
}
displayMenu();
std::cout << std::endl;
std::cin >> choice;
}

switch (choice) {
void addition() {
case 1: {
double a, b;
int limit;
std::cout << "Enter two numbers to add: ";
std::cout << "Enter the limit to count up to: ";
std::cin >> a >> b;
std::cin >> limit;
std::cout << "Result: " << a + b << std::endl;
countUp(limit);
}
break;
}
void subtraction() {
case 2:
double a, b;
addition();
std::cout << "Enter two numbers to subtract: ";
break;
std::cin >> a >> b;
case 3:
std::cout << "Result: " << a - b << std::endl;
subtraction();
}
break;
case 4:
void multiplication() {
multiplication();
double a, b;
break;
std::cout << "Enter two numbers to multiply: ";
case 5:
std::cin >> a >> b;
division();
break;
case 6:
std::cout << "Exiting the program." << std::endl;
break;
default:
std::cout << "Invalid choice. Please try again." <<
std::endl;
}
} while (choice != 6);

return 0;
}

You might also like