problem..

I was writing a calculator then when I decided to compile it (unfinished) it says "undeclared doPrint" and many other errors..

Code:
//#include <stdafx.h>
#include <iostream>
using namespace std;

int main()
{
cout << "Calculator 1.0" << endl;
cout << "Choose the operation" << endl;
cout << "1. Addition" << endl;
cout << "2. Subtraction" << endl;
cout << "3. Multiplication" << endl;
cout << "4. Division" << endl;
int select;
select=0;
cin >> select;
if (select==1);
{
doPrint()
}
else
{
wrong()
}

return 0
}











void doPrint()
{
cout << "Enter Number: " << endl;
int x;
x=0;
cin >> x;
}

int add1()
{
q=doPrint()
w=doPrint()
cout << "Answer is: " << q+w << endl;
system("pause>nul");
}

void wrong()
{
cout << "Please choose only 1, 2, 3 or 4" << endl;
system("pause");
main()
}





Last edited on
You need to forward-declare your functions. When it gets to the part you use doPrint, the compiler still doesn't know that the function exists, so you have to tell it that it does. You also have forgotten your semicolons.

Calling main is generally frowned upon, too, as is system("PAUSE").
So, you put ; where you are not supposed to, and you don't put it where you are supposed to :D
if (select==1); no
doPrint() yes
return 0 yes...

1
2
q=doPrint();
w=doPrint();

q and w aren't declared, you have to put:
1
2
int q = doPrint();
int w = doPrint();

But doPrint function returns nothing (void), so this assignment is illegal.
You should change return type for doPrint from void to int and to return x.

Your add() function returns nothing also, so change it's return type to void or return something.

You should call add1 function if select == 1, not doPrint.

Pls next time use [code] tags.
Last edited on
Topic archived. No new replies allowed.