0

Why is my calculator program not outputting any numbers?

I am trying to make a calculator program that will ask for what operation the user wants to perform and then input two numbers. The calculator will then perform the function and return the value to the user. The problem is, the calculator won't output any numbers. I'm confused why this is happening. Here is what I have so far: #include <iostream> using namespace std; int a = 0; int b = 0; string y; int add(int a,int b) { return (a + b); } int subtract(int a,int b) { return (a - b); } int divide(int a, int b) { return (a/b); } int multiply(int a, int b) { return (a * b); } int main() { cout << "MENU" << endl; cout << "1. Add" << endl << "2. Subtract" << endl << "3. Multiplication" << endl << "4. Division" << endl << endl; cout << "What do u want to do? (Choose one of the aforementioned options 1-4)" << endl; int x = 0; cin >> x; cout << "Alright, what numbers do you want?" << endl; cin >> a; cin >> b; switch(x) { case 1: add(a,b); break; case 2: subtract (a,b); break; case 3: multiply(a,b); break; case 4: divide (a, b); break; } }

8th Jul 2017, 1:07 PM
Somebody that you used to know
Somebody that you used to know - avatar
3 Réponses
+ 1
Because you didn't print your answers. in switch case try using int a=add(a,b); cout<<a; break; like this do for all. Hope it works..
8th Jul 2017, 1:11 PM
Previn Kumar
Previn Kumar - avatar
+ 1
you could use something like this void add(int a, int b) { cout << a - b << endl: }
8th Jul 2017, 6:40 PM
johan beimers
johan beimers - avatar
0
I don't want to be mean but I'll explain why I don't like your structure is kind of difficult to understand, maybe you can use a class and organize your code, use commentaries. Maybe you have some debilities in fundamental skills that you don't know. I was trying to fix your code :) And I'll maybe post here later
9th Jul 2017, 7:32 AM
María José
María José - avatar