error C2143 syntax

The error message says I'm missing a semicolon before a parentheses. Line 31 is a for loop, the statement before that is a cout, and before that a variable declaration. I have tried moving braces but that creates more error msgs. I'm not sure it will compile after this even but need to get by this to work on it.
Is there a compiler out there that would be better for troubleshooting these things? I'm trying to learn as fast as I can but...

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
Program abilities
*/
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

//Function Prototypes
void fallingDistance();
double getTime();
double Gravity ();

int main()
{
	//declare variables
	double time, grav;

	fallingDistance();		 //will show distance fallen every second for 10 seconds
	time = getTime();		//get the number of seconds from user
	grav = Gravity();		// will convert distance to time
		
	return 0;
}
void fallingDistance (double time, double dist, double grav)
{
	double i=1;
		cout << " This program will show you how far an object will fall \n" <<
			"in a given amount of time using the formula: distance = 1/2gt^2. \n" << endl;

		for (i=1, 1<=10, i++)
		{
			time=i;
			dist = grav * pow(time, 2);
		}	
}
double getTime()
{
	double gottasec;
		cout << "Please enter the number of seconds you would like to fall: " << endl;
		cin>>gottasec;
		return(gottasec);
}
double Gravity(double grav)
{
		grav = 9.8;
			return (grav);
}
for loops have semicolons to separate the sections, not commas:

1
2
3
for (i=1, 1<=10, i++)  // <-  bad

for (i=1; 1<=10; i++)  // <-  good 


AAAAAHHHHHHH!!!!!!!

Thank you! Not only do I feel stupid...It's online.
I'm back and it seems the same but different.
Line 20 and 21. It states these will not take zero for an arguement yet when I added "double", "double with ; seperators", it tells me I need a ")". I have read the functions and parameters in this sites library and can find no instance of a parameter like I'm doing. Is it wrong? any other way? or am I just missing something AGAIN??



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
35
36
37
38
39
40
41
42
43
44
45
46
47
48

/*
Program abilities
*/
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

//Function Prototypes
void fallingDistance(double time, double dist, double grav);
double getTime(double dist, double gottasec);
double Gravity (double grav);

int main()
{
	//declare variables
	double time, grav;

	time = getTime();			//get the number of seconds from user
	grav = Gravity();			// will convert distance to time
		
	return 0;
}
void fallingDistance (double time, double dist, double grav)
{
	double i=1;
		cout << " This program will show you how far an object will fall \n" <<
			"in a given amount of time using the formula: distance = 1/2gt^2. \n" << endl;

		for (i=1; 1<=10; i++)
		{
			time=i;
			dist = grav * pow(time, 2);	
		}	
}
double getTime(double dist, double gottasec)
{
		cout << "Please enter the number of seconds you would like to fall: " << endl;
		cin>>gottasec;
		cout << "You will fall " << dist << "for every " << gottasec << "that you fall. " << endl;
		return 0;
}
double Gravity(double grav)
{
			return grav = 9.8;
}
Try change the functions from:
1
2
double getTime(double dist, double gottasec);
double Gravity (double grav);


to :

1
2
double getTime();
double Gravity ();


at line 12 and 13 (also on line 37 and 44)
You have declared getTime and Gravity functions to take 2 arguments and 1 argument respectively.
Yet in line 20 and 21 when those functions are called, you dont 'pass' any arguments. Your error on compiler is probably saying 'your function does not take 0 arguments' (or some such).

Also, looking at line 37, the getTime function argument 'double gottasec' seems redundant considering you are asking for input from user ie; cin>>gottasec. Are you passing gottasec to the function OR are you asking for gottasec as an input??

Also, fallingDistance function is not even called, anywhere in the program..? The program will not just continue on once it reaches the end of int main. Crucially, it looks like fallingDistance function is the 'maths' of the whole program and therefore needs gottasec passed to it and the grav returned from gravity function. Then it needs to do the gravity logic calculation and output result. Not even sure why you have a for loop for this.
sounds like I'm doing it backwards.
I need a function called "fallingDistance that asks for time fallen in secnds as an argument. Then returns the distance (in meters) that the object has fallen during the selected time.
Write a program that demonstrates the function by calling it in a loop that passes the values of 1-10 as arguments and displays the return value.
I used an example from the book where they were changing fluid ounces to cups.
The for loop is to use the formula to display the distance fallen through ten seconds.
I was hoping to work out the errors on an ongoing basis but it feels like a chicken chasing flies in a manure pile. Everytime I fix one two more hatch.
It looks like my getTime function is more true to the problem (based on your questions) and the for loop needs to be incorporated, I'm gonna try to get the formula into Gravity() and call it from there. I'm also gonna try to modify the loop to call the function and apply it to the 10 seconds which I thought at the time was like a menu option/example.
Back to the drawing board.
I hope I am progressing and not regressing. I chopped a lot out trying to get the one function the problem asks for with the associating call from the return. It compiles to a blank screen. Now I am at a spot I don't seem to "get". I thot using 'fall as a returned value would give me what I needed from my 'fallingDistance function. Obviously not.

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
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

//Function Prototypes
double fallingDistance();

int main()
{
	//declare variables
	double time, fall = 0;

   fallingDistance();						 
		cout << "Please enter the number of seconds you would like to fall: " << endl;
		cin>>time;
		cout << "You will fall " << fall << "for every " << time << "that you fall. " << endl;
	return 0;
}
double fallingDistance ()
{
		double i=1, fall, time, grav = 9.8;
		for (i=1; 1<=10; i++)
		{
			time=i;
			fall = grav * pow(time, 2);	
		}

			return fall;
}
It looks as though this will not do anything, because you call fallingDistance() almost first thing in int main but dont pass any arguments to it. You've eliminated all arguments from fallingDistance function, not sure why, considering that both fall and time are going to be needed in the fallingDistance maths.

Probably needs fallingDistance called after user has inputted 'fall' amount.
You then call fallingDistance and pass 'fall' variable as an argument. This would need to be prototyped in line 7 and added to that function on line 20 and when you call it of course.

Then in that falldist func you carry out the logic, ie; multiply fall by gravity etc.


I was looking for brevity and thot I had too much un-needed coding.
I moved line 14 to 17, added double fall to line 7 (prototype) and 20, removed fall in line 22 and added time function but while it compiles still accpts only the time and doesnt execute.

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
35
36
37
38
39
40
41
/*
Program abilities
*/
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

//Function Prototypes
double fallingDistance(double);
double getTime(double, double, double);

int main()
{
	//declare variables
	double time, fall=0;//should fall (the distance user will fall after inputting time) be zero?

   						 
		cout << "Please enter the number of seconds you would like to fall: " << endl;
		cin>>time;//amount of time falling
		fallingDistance(fall);
		cout << "You will fall " << fall << "for every " << time << "that you fall. " << endl;
	return 0;
}
double fallingDistance (double fall)
{
		double i=1, time, grav = 9.8;
		for (i=1; 1<=10; i++)
		{
			time=i;
			fall = grav * pow(time, 2);	
		}

			return fall;
}
double getTime(double time, double grav, double dist)
{
		time = sqrt (2*dist/grav);
		return time;
}
looking at the code and the response(or lack of) it seems my input is not getting into the right spot to be part of the equation which would output fall and or time. Even knowing that I can't see the solution
It compiles but I don't have the fallingDistance function operating yet. I get time from the return call but not fall. Here is the semi- working code, Line 20 is where the F10 line by line compile stops and hangs, I'm still trying everything I can think of. And thanks for everything so far. It has made a difference.

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
35
36
37
38
39
40
/*
Program abilities
*/
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

//Function Prototypes
double fallingDistance(double, double, double);
double getTime(double);

int main()
{
	//declare variables
	double time, fall=0, grav = 9.8;
				 
		cout << "Please enter a number: " << endl;
		cin>>time;
		fallingDistance( fall, time, grav);
		cout << setprecision(2) << showpoint << fixed;
		cout << "You will fall " << fallingDistance << " meters for every " << time << " seconds that you fall. \n" << endl;
	return 0;
}
double fallingDistance(double fall, double time, double grav)
{
		double i=1;
		for (i=1; 1<=10; i++)
		{
			time=i;
			grav = 9.8;
			fall = grav * pow(time, 2);	
		}
			return fall;
}
double getTime(double time) 
{
		return time;
}
Sorry mate, but this is a real mess.
Line 10; prototype should be the same as line 25. You've just written double, double, double.
Line 11; prototype should be the same as line 36.

Line 20 You are passing 'fall' into fallingDistance function. Not sure why? You've initialised it as 0 in line16 so basically it doesnt really make any sense to me to pass it into a function, if you know what I mean. Its not doing anything.
Also, line 20 should be like this double getfall = fallingDistance (time, grav);
Then in line 22 you would write cout << "You will fall " << getfall << //blah blah

Line 21 ?? Sorry I havent seen this in any of your other prior codes?? Not sure what you are doing here?
The setprecision function sets the maximum number of digits to be displayed for a number... why do you need that here?

Line 28; for (i=1; 1<=10; i++) should be for (i=1; i<11; i++) The i replaces the 1.

And basically the whole fallingDistance function doesnt make sense to me. I really am not sure what you're doing here. Wouldn't it be better to have a simple calculation ie the time * 9.8 per second per second formula and return it to the 'getfall' call in int main.
Not sure of the physics formula that should be in this function but here is a link
http://en.wikipedia.org/wiki/Equations_for_a_falling_body

Also, again the getTime function has not been called. And really, I guess there is no need to because 'time' is a user input in int main. I am not sure why you would pass it to this function and then immediately return it to where-ever??

Also, you really dont need to pass 'grav' into fallingDistance function either because the internal logic of that function should have the 9.8 as part of its calculation. In fact I note you have it initialised in line 16, pass it to the function in line 20 and then re-initialise it in line 31.
I think you really need to rethink the fallingDistance function. Drop the for loop approach and have a simple bunch of equations that use the time as inputted in main().
Good luck.

Last edited on
I wrote the distance fallen formula from wiki as a calculation in the fallingDistance function.

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
#include<iostream>
#include<cmath>
using namespace std;

double fallingDistance(double time);

int main()
{
	double time; 
	cout << "Please enter the number of seconds you would like to fall: " << endl;
	cin>>time;
	double getfall = fallingDistance(time);
	cout << "You will fall " << getfall << " metres over the " << time << " seconds that you fall. " << endl;
  					 
cin.ignore().get();
return 0;
}

double fallingDistance(double time)
{
	
	double power = pow(time, 2);
	double fall = (4.9*power);

	return fall; 
}
Last edited on
Thanks to everybody for a successful venture. Here is the completed code. Please let me know of any presentation errors you see. I'll need to know what is and isn't good form.

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
/*
This program shows the rate of falling in meters per second using the formula shown.
It uses the numerical values called to show what it does through 10 iterations
*/


#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

double fallingDistance(double, double, double);		//function prototype

int main()
{
	double dist=0, time =0, grav = 9.8;				//declare variables
	fallingDistance(dist, time, grav);

	return 0;

double fallingDistance(double dist, double time, double grav)	//function and formula
{
	int i = 1;

	for (i=1; i <= 10; i++)
	{
		time=i;
		dist=0.5*grav*pow(time,2);
		cout << "You've fallen " << dist << "\t meters in " << time << " seconds." << endl;
	}
	setprecision(2);
	return dist;
}
Well done.

1. Closing brace needed line 20.

2. Put cin.ignore().get(); in line 18 to stop the window closing
as soon as you compile.

3. Without having the user inputting the time, the for-loop makes sense
now. Before you wanted user input.

4. I still dont get why you are passing two variables; dist and time, both
0, into the fallingDistance function?
If you got rid of them and just put 'double' in front of time (line 27) and declared 'double dist;' in
on line 24 you achieve the same with less... in fact, get rid of return dist; and put return 0; on line 32, then you can just put double in front of dist on line 28. setPrecision(2) BTW is not doing anything.
(returning dist from the function is not doing anything!)

5. Also I think double fallingDistance(double, double, double); is considered
'bad form' at least thats what I was told a while back. Apparently good form
is to have double fallingDistance(double dist, double time, double grav);
as the full prototype.
Last edited on
I thought I'd better check that last point I made, just to verify what I was told
several months back. In most sites it says;
'in the function prototype the names of the arguments are dummy variables and therefore optional,
and neither do the argument names have to match those of the function definition, but for the sake of clarity and readability most programmers include the names of the arguments as written in the definition.'
Topic archived. No new replies allowed.