954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

new programmer stuck with 'if statements..

Hello All,

I'm very new to C++ and programming in general and am having probelms with an assignment i have been set. I've been using ?Blood dev C++? ( i dont know if this is any good?) I have basically finished the program and am getting one syntax error that i cannot figure out. In desperation i post here in order to pick your brains :o

Essentially the problems is on line 54:

int twentynote = int rtotal / 2000; // work out if various amounts fit.

the error as it it shows on screen:
in function 'int main(int, char**)':
syntax error before '/' token.

I haven't come toask for any help with the coding (no matter how bad it is :D ) just some help with this error would be great. the code is below.


#include
#include

using namespace std;

int main(int argc, char *argv[])

{
float total;
float flint;
int rtotal;

int twentynote;
int tennote;
int fivenote;
int twocoin;
int onecoin;
int fiftypcoin;
int twentypcoin;
int tenpcoin;
int fivepcoin;
int twopcoin;
int onepcoin;

{
cout<<"\nPlease enter amount required in the format Pounds and Pence '££.pp' ";

cin>>total;

flint = total * 100;
rtotal = (int)flint;
}

do{

int twentynote = int rtotal / 2000; // work out if various amounts fit.

if twentynote > 0
{
int rtotal = int rtotal % 2000;
}
}


{
int tennote = int rtotal / 1000;
if tennote > 0
{
int rtotal = int rtotal % 1000;

babablacksheep
Newbie Poster
4 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Remove the int from in front of rtotal. Type names are (for the most part) only used in declarations and type casts. Because your use is neither of those, it's a syntax error. Of course, the code you've posted has other syntax errors as well.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Thx for the reply Narue,

I've done as you have suggested and the compiler error has moved to the next line:

syntax error in '>' token.

is this related to the other syntax errors you have spotted? any chance of spelling them out for a noobie? : :lol:

babablacksheep
Newbie Poster
4 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

sorry i forgot to say - i have removed all the 'int ' entrys.

babablacksheep
Newbie Poster
4 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Let's solve this one error at a time, use

if (twentynote > 0)

hint, conditional statements should be in (). That goes for all your if and while.

... and oh yes, Dev-C++ is very good for student use!

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Hi Chaps,

I think I have sussed it. It was the int entrys as narue said and also my if staetemnt wasnt in brackets :o ahh well you live and learn :cheesy:

thX

babablacksheep
Newbie Poster
4 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Hey babablacksheep

I don't know if this will be of any help to you, but try this:

int twentynote, tennote, fivenote....;

This way you can 'int' everything in one line. Obviously you should only do this if all of the variables you are 'int'ing are the same (eg string)

(",)

xinix
Newbie Poster
10 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

>This way you can 'int' everything in one line.
You can "declare" everything with the same type on one line. The wording you used is potentially confusing. Also, while vertical space is abundant, horizontal space is more valuable. Learn to use it wisely. For example, it's widely accepted that single line declarations should consist of closely related variables, if they're used at all.

In this case, an array would be better than any measure of formatting of multiple variables.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You