Of Files and Algorithms

Good people of C++ forums I'm writing an advanced calculator this time. It does 2D area, surface area, lateral and curved surface area, pythagoras, and volumes. I have decided to do the follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Main.cpp

#include <iosteam>

using namespace std;
//No using namespace in the actual code
//I know its a bad thing
//Thanks for telling me that guys

int main ()

{

char formulaChoice;

//.....

switch (formulaChoice)
{

case '1':
int add ()

//its not int add ()';', right?
//....

}
return 0;
}

Not much in that. But what I want to do is place options for 1-9 and then from A-Z (only one character in a char, right?). Now for the main thing :D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//Formulae.cpp

#include <iostream>
#include <cmath>
//No sqrt in main.cpp
//So putting cmath here
//Btw cmath vs math.h?

using namespace std;

int add ()

{

int num1, num2;
//...
cout << num1 + num2 << endl;
}

//...

int PGT ()

{
//...
}

//... 

return 0;
}

//Srry for lots of '...'s

So is that valid? Also as you noticed I put all the formulae in a separate file and the other stuff with the main () function in another. So now I would like to include the formulae.cpp in main.cpp WITHOUT a compiler! My PC is mush and my tab is out for maintainence for the next 2 weeks. So I would be using cmd or an online compiler to do so. So please suggest the methods with the online compiler or the cmd line! Thanks!
Line 22 of the top code:
int add ()
is this an attempt to call the function add?
The function is called like this:
add();
or, if you want to capture the returned value,
int x = add(); (although I see that your add function doesn't actually return anything, although it says it does)

Second file looks fine right up until the return 0; at the end of Formulae.cpp. return goes in functions. That return 0; isn't in a function.
Last edited on
Before you even start putting "stuff" in other files you should fully understand the difference between definition and declaration and do some reading on include files.

It seems that you have not provided or attempted to make a real start, keyboard input, use of functions and simple operator knowledge should be a base requirement for this assignment.

The fact you ask the question "its not int add ()';', right?" and the local variables instead of parameters regarding the add function means you have no understanding of functions, return types and parameters.

Dive back in to those books and or catch up on some tutorials on this great site or google, with a few keywords I was able to find plenty of resources that would solve this for me if I had not known already.

Good luck!
Topic archived. No new replies allowed.