error: expected primary-expression before 'float'

Hey,
I found this site because I wanted to start C++. I read half the tutorials and made a program with the info that I have. The part i screwed up on are the functions. I wrote them in but when they didn't work I decided to not use them, but they still exist. I used one near the bottom of my code. I keeping getting the error: expected primary-expression before 'float' and im not sure what I am doing wrong. I probably didn't code this in the best manner but oh well. what can I say im a noob.:) help would be greatly appreciated, and any other suggestions!
Thanks



#include <iostream>
#include <string>

using namespace std;

long operation;
float a;
float b;
float y;
float x;
float s;
float inter; // intercept
int c; // if == 1 goto
int k;
float Ia; //numerator
float Ib; //denominator
float r; //result after the ia/ib
int t; //if == 1 move on
float l;
float m;


int add (int Aa, int Ba)
{
Aa = a;
Ba = b;
int adda;
adda=Aa+Ba;
return (adda);
}
int dived (int Da, int Db)
{
Da = a;
Db = b;
int d;
d=Da/Db;
return (d);
}
int multiply (int Ma, int Mb)
{
Ma = a;
Mb = b;
int r;
r=Ma*Mb;
return (r);
}
int subtraction (float Sa, float Sb)
{
Sa = l;
Sb = m;
int s;
s=Sa-Sb;
return (s);
}
//int figure (int Ic, int Id)
//{
//cout << "What is the numerator?";
//cin >> Ic;
//cout << "What is the denominator?";
//cin >> Id;
//s = Ic/Id;
//return(s);
//}
int main ()
{
start:
cout << "What operation do you want? \n 1 = Addition \n 2 = Subtraction \n 3 = Division \n 4 = Multiplaction \n 5 = Y=mx+b \n 6 = Quit \n";
cin >> operation;
if (operation==1)
{
cout << "You have two numbers. \n";
cout << "What should number one be? \n";
cin >> a;
cout << "What should number two be? \n";
cin >> b;
cout << a+b << "\n";
c = 1;
if (c==1) goto start;

}
if (operation==2)
{ cout << "You have two numbers. \n";
cout << "What should number one be? \n";
cin >> a;
cout << "What should number two be? \n";
cin >> b;
cout << a-b << "\n";
c = 1;
if (c==1) goto start;
}
if (operation==3)
{
cout << "You have two numbers. \n";
cout << "What should number one be? \n";
cin >> a;
cout << "What should number two be? \n";
cin >> b;
cout << a/b << "\n";
c = 1;
if (c==1) goto start;
}
if (operation==4)
{
cout << "You have two numbers. \n";
cout << "What should number one be? \n";
cin >> a;
cout << "What should number two be? \n";
cin >> b;
cout << a*b << "\n";
c = 1;
if (c==1) goto start;
}
if (operation==5) {
cout << "Enter value of X \n";
cin >> x;
cout << "What is the equation? \n Enter the slope not in fraction form! Need help with a decimal/full number? \n Press 1 if not press any number key. \n";
cin >> k;
if (k!=1) {
goto intercept;
}
if (k==1) {
cout << "What is the numerator?";
cin >> Ia;
cout << "What is the denominator?";
cin >> Ib;
r = Ia/Ib;
cout << r;
goto intercept;


}
intercept:
cout << "\n Please enter the slope.";
cin >> s;
cout << "\n What is the y-intercept?";
cin >> inter;
y = s*x+inter;
cout << "\n Y=" << s << "*" << x << "+" << inter << " \n Y is equal to " << y ;
cout << "\n Are you ready to move on? \n Press 1 when ready.";
cin >> t;
if (t==1) {
c=1;
}
if (c==1) {
goto start;
}

}
if (operation==6) {
return 0;
}
if (operation==7) {
cout << "Pick the first number.";
cin >> l;
cout << "Pick the second number.";
cin >> m;
cout << subtraction ( float Sa, float Sb); // This is where im getting expected primary-expression before 'float'
}
}
That is not how you call a function.
http://cplusplus.com/doc/tutorial/functions/

Other things I noticed:
- Your variable names are not very descriptive
- You use the goto keyword in cases where it is not necessary (generally use a loop instead)
- You use several magic numbers
- Your functions create many temporary variables for no reason
Thanks! Yea I wasn't really sure what I was doing I was just kind of messing around. Thanks for the tips. What are magic numbers?
http://en.wikipedia.org/wiki/Magic_number_%28programming%29
Basically, you are putting constants in the code with no meaning attached to them. For example, 7 could mean anything, but you have arbitrarily assigned it to subtraction. Make a constant that stores the value 7, giving it a descriptive name.
Im sorry, Im really not getting this function thing. When you call a function do you just type in the function name followed with the int's? Iv read the functions tutorial over and over, but somehow im not understanding.
The syntax for calling a function is this:
function_name(paramter1, paramter2)
For example, to call the subtraction function with parameters "l" and "m" as I think you were intending to do, you write:
subtraction(l, m)
Thank you! I fixed that error, however I received another one, which was too many arguments to function.
(btw thank you so much for helping a helpless noob)
That error is pretty self-explanatory. You are passing more arguments to function than it can accept. For example: subtraction(a, b, c, d) would give this error because you are passing 4 arguments when the function has been defined to only take 2.
Thank you soooooo much for helping me make me little fail calculator app.!
Topic archived. No new replies allowed.