help with error C2143: syntax error : missing

December 16, 2009 at 09:33:29
Specs: Windows Vista
My assignment was to create a code on C++
that can solve the problem where a boat is
crossing a river. I had to do it in steps, the first time I plugged in numbers and was told if I
went over a waterfall or not. The second time I
had to add a while loop so I can rerun the
program. Finally I had to change the program
to deal with varying water velocity and varying
river width. I'm pretty sure I was on the right
track, but I keep getting these error
messages:

error C2143: syntax error : missing ')' before ';'

error C2143: syntax error : missing ')' before ';'

error C2059: syntax error : ')'

error C2059: syntax error : ')'

error C2143: syntax error : missing ')' before ';'

error C2059: syntax error : ')'

warning C4390: ';' : empty controlled

error C2143: syntax error : missing ')' before ';'

error C2059: syntax error : ')'

warning C4390: ';' : empty controlled

error C2143: syntax error : missing ')' before ';'

error C2059: syntax error : ')'

warning C4390: ';' : empty controlled statement found; is this the intent?


I don't see anything wrong with my parentheses and I can't figure it out. I can post the whole assignment if necessary, but here's what I had so far.


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

int main()
{


float dwf, nsteps, ddown, wriver, vrow, vwater,
dx, dy, x, y;
#define dwf 50;
char more;
do
{
cout << endl << "Enter the river's width ";
cin >> wriver;
cout << endl << "Enter the rowing velocity ";
cin >> vrow;
cout << endl << "Enter the water flow velocity
";
cin >> vwater;
cout << endl << "Enter the number of steps ";
cin >> nsteps;

ddown=wriver*(vwater/vrow);
cout << ddown;
dy=wriver/nsteps;
cout << dy;

x = 0;
y = 0;

while ( (y <= wriver) && (x <= dwf) );
{
dx=dy*(vwater/vrow);
cout << dx;
y = y + dy;
x = x + dx;
}

if (y == dwf) {
cout<<" Congrats! You did not go over the waterfall! ";
}
if (x == dwf) {
cout<<" You just made it! ";
}
if (x > dwf) {
cout<<" Aww, you went over the waterfall. ";
}
cout << endl << "Do you wish to run again?
(y/n) ";
cin >> more;
} while ((more == 'y') || (more == 'Y'));

return 0;
}

This is what I had before I tried to deal with the varying water velocity and river width. This part worked out fine:

int main();
#include <iostream>;
#include <cmath>;
using namespace std;

int main()
{

#define dwf 50
int wriver, vrow, vwater, dx, dy, x, y, nsteps;
float ddown;
char more;
do
{
cout << endl << "Enter the river's width ";
cin >> wriver;
cout << endl << "Enter the rowing velocity ";
cin >> vrow;
cout << endl << "Enter the water flow velocity ";
cin >> vwater;

ddown=wriver*(vwater/vrow);


cout << ddown;


if ( ddown < dwf ) {
cout<<" Congrats! You did not go over the waterfall. ";
}

else if ( ddown == dwf ) {
cout<<" You just made it! ";
}
else {
cout<<" Aww, you went over the waterfall. ";
}
cout << endl << "Do you wish to run again? (y/n) ";
cin >> more;
} while ((more == 'y') || (more == 'Y'));

return 0;
}


See More: help with error C2143: syntax error : missing

Report •


#1
December 16, 2009 at 11:48:31
There are reasons we call the preprocessor evil. This is one of those reasons.
float dwf, nsteps, ddown, wriver, vrow, vwater, dx, dy, x, y;
#define dwf 50;

Should be:
float nsteps, ddown, wriver, vrow, vwater, dx, dy, x, y;
const float dwf = 50;


Report •

#2
December 16, 2009 at 12:11:42
Thanks, that really helped a lot and got rid of all of the errors. I
now have the following issues though:
error C2143: syntax error : missing ';' before 'constant'
error C2734: 'Dwf' : const object must be initialized if not extern
error C2373: 'Dwf' : redefinition; different type modifiers
Any ideas? I'm probably going to go get help on this one later
today.

Report •

#3
December 16, 2009 at 13:09:34
Look at the line before your const statement. You're missing a semicolon.

Report •

Related Solutions

#4
December 16, 2009 at 14:14:54
Thank you for all your help. In the end I decided that instead
of making Dwf a constant, I made it so you can pick the
distance to the waterfalls. Also for future reference, I have a
semicolon at the end of my while loop so although that did not
come off as an error, what was inside the loop never
computed. Now my program runs well. Here is my finished work:


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

int main()
{
float Dwf,Wriver, vrow, vwater, dx, dy, x, y;
int nsteps;
char more;

do
{
cout << endl << "Enter the river's width ";
cin >> Wriver;
cout << endl << "Enter the rowing velocity ";
cin >> vrow;
cout << endl << "Enter the water flow velocity ";
cin >> vwater;
cout << endl << "Enter the number of steps ";
cin >> nsteps;
cout << endl << "Enter the Distance To the falls";
cin >> Dwf;

dy=Wriver/nsteps;

x = 0;
y = 0;


while ((y <= Wriver) && (x <= Dwf))
{

dx=dy*(vwater/vrow);
y = y + dy;
x = x + dx;
cout<<"X="<<x<<" Y="<<y<<endl;

}
cout<<endl;

if ((x >= Dwf)) {
cout<<" You did not go over the waterfall. ";
}
else {
cout<<" You went over the waterfall. ";
}

cout<<endl;
cout << endl << "Do you wish to run again? (y/n) ";
cin >> more;

}while ((more == 'y') || (more == 'Y'));

return 0;
}


Report •


Ask Question