Author Topic: What's wrong with my calculator? :(  (Read 1117 times)

Code: [Select]
#include <iostream>

using namespace std;

int main() {
    int a;
    int b;
    int input;
    int result;
    cout << "Enter in a number\n";
    cin >> a;
    cout << "Now enter a second in\n";
    cin >> b;
    cout << "Now choose which operation you'd like\n";
    cout << "1. Addition\n";
    cout << "2. Multiplication\n";
    cout << "3. Subtraction\n";
    cout << "4. Divison\n";
    cin >> input;
    if (input = 1) {
        result = addition (a,b);
                    }
    else if (input = 2) {
        result = multiplication (a,b);
    }
    else if (input = 3) {
        result = subtraction (a,b);
    }
    else if (input = 4) {
        result = division (a,b);
    }
    cout << "The operator specified returned " << result << ".\n";
    return 0;
}

int addition(int a, int b) {
    return (a+b);
}

int multiplication(int a, int b) {
    return (a*b);
}

int division(int a, int b) {
    return (a/b);
}

int subtraction(int a, int b) {
    return (a-b);
}
I get an error when I try to build in netbeans saying that lines 21, 24, 27 ,and 30

(the result = <functionname> ones)

that say: error: 'addition/multi/etc' was not declared in this scope

I've tried several things and checked several programming sites yet none offered help that relate to this problem.

And yes, I know this is really basic. I wanted to make sure I understood functions before I start using classes/structures

wut
Since when do calculators read scripting languages?
Gtfo with your rich people calculators. ;-;

wut
Since when do calculators read scripting languages?
Gtfo with your rich people calculators. ;-;
It's a calculator I coded, and it's in C++

are you stupid?


wut
Since when do calculators read scripting languages?
Gtfo with your rich people calculators. ;-;
TI-80+?


It's a C++ application that is a calculator. 

You're supposed to state the functions before your main function.

Looks like it has a case of...
AIDS.

forget dammit I used the wrong line again.

Looks like it has a case of...
AIDS.

forget dammit I used the wrong line again.
Code: [Select]
using namespace std;

int aids(int a, int b) {
int poo;
poo=a-b
return poo;
}

int main() {
int lol;
lol = aids (3,4);
cout << "YOU GOT" << lol << "AIDS";
return 0;
}
rite?



Badspot

  • Administrator
You are using functions before they are declared.

http://en.wikipedia.org/wiki/Function_prototype

holy shiiiiiiiit
why am I so surprised at that.
And did you ban that whatever guy with that richard in his avatar or not.

holy shiiiiiiiit
why am I so surprised at that.
And did you ban that whatever guy with that richard in his avatar or not.

I was just about to ask this.

And this scripting stuff, how do you memorize it? lol.

And this scripting stuff, how do you memorize it? lol.
I think about it without the brackets and stuff, and put words into a sentence.
It lets me remember better what they do.
But I can never remember where to put brackets and line breaks and stuff.