Newbie needs advice Please...

Started by
4 comments, last by frankiej 19 years, 6 months ago
Hi everyone Can someone please help me with the below program which I am programming at evening college on a beginners course. We have been told to programme a simple info sheet for a user to fill in but for some reason I keep getting the below 5 errors. I am currently using the Bloodshed complier to practise on. 9 new1.cpp base initializers not allowed for non-member functions 10 new1.cpp no base initializers given following ':' 10 new1.cpp parse error before `void' 35 new1.cpp parse error before `<' 52 new1.cpp parse error before `=' THE PROGRAMME: #include <stdio.h> #include <conio.h> #include <iostream.h> int InpAccNum (void); int InpNumWks (void); float SetRent (void); float CalcBill (int Lnwks, float Lrpw): void PressAKey (void); void cls (void); void Underline (int nn); int main() { int accnum,nwks; float rpw,totbill; accnum = InpAccNum(); nwks = InpNumWks(); rpw = SetRent(); totbill = CalcBill (nwks, rpw); cout << "\nInvoice"; printf ("\nAccount number : %d", accnum); printf ("\nRent per week : %10.2f", rpw); printf ("\nTotal bill : %10.2f", totbill); return 0; } //main int InpAccNum(void) { int Laccnum cout << "\nEnter account number : "; cin >> Laccnum; return Laccnum; } //Inp Accnum int InpNumks(void) { int Lnwks; cout << "\nPlease enter number of weeks: "; cin >> Lnwks; return Lnwks; } //InpNwks float SetRent(void) { float Lrpw Lrpw = 3.60; return Lrpw; } //SetRent float Calcbill(int Lnwks, float Lrpw) { float Ltotbill; Ltotbill = Lnwks * Lrpw; return Ltotbill; } //Calcbill void PressAKey (void) { cout <<"\nPress any key to continue"; getch(); } //PressAKey void cls (void) { clrscr(); } //cls void underline(int nn) { int ii; cout <<"\n"; for (ii = 1; ii <=nn; ii++) cout <<"_"; } //Underline
Advertisement
float CalcBill has a colon at the end not a semicolon.

basically you have a typo.


you're missing semicolons at: float Lrpw , int Laccnum also

Beginner in Game Development?  Read here. And read here.

 

Nothing big, you just made a few simple typos.

First off, on line 9:

float CalcBill (int Lnwks, float Lrpw):


Note that at the end of that line you've got a : instead of a ; . What this does, since you're using C++, is tell the compiler you're defining a member function of some sort of a class (to make a long story short). But since you're obviously not, and it's an illegal scope for doing it anyway, it goes insane. This is what's causing all the parse errors you're getting.

The second error, on line 43 and 52:

        int Laccnum ...int Lrpw


Notice that you've got no ; at the end of that line - therefore C++ continues processing the next line as part of this statement, which of course just does not form a valid statement of any kind. So you get more errors. Missing ; and confusing them with : is absolutely the most common C/C++ gotcha. I've spent hours looking for one.

A few suggestions... conio ties your code to DOS. I couldn't compile it on my linux (not that I needed to to find the error tho). Also, using printf() within a C++ program is considered bad form, as it can cause problems between the libc and libc++ libraries. You can accomplish the same thing with cout that you can with printf. For example,

printf("An integer: %i", integerVariable);....cout << "An integer: " << integerVariable << "\n";


Overloading is one of the fabtastic things about C++...

hope all that helped.
=========================Buildium. Codium. Fragium.http://www.aklabs.net/=========================
Thank you for the replys, I tell you this programming isnt easy wow, anyway I have just compiled my work and have no errors which is a good, but it still wont show me my results.
I seem to have problem with the Linker any ideas?? as this all runs fine on my college PC and we use "Turbo" Complier could this be the reason?

MY LINKER ERRORS:

C:\WINDOWS\TEMP\cc3HAcgb.o: In function `main':
//c/dev-c_~1/untitl~1.cpp:20: undefined reference to `InpNumWks(void)'
//c/dev-c_~1/untitl~1.cpp:22: undefined reference to `CalcBill(int, float)'


actually you have to make sure that EVERYTHING is spelled the same. you have a function declaration as float CalcBill and the function body float Calcbill.

notice the different spellings? C and C++ are case-sensitive. therefore something like:

int Number = 0;
int number = 0;

are two different variables.

that's what the errors you have now are about.

Beginner in Game Development?  Read here. And read here.

 

I would just like to say thanks to everyone who has answered my question, my program is now running fine. Just another quickie if possible. One thing I cant get my head around is what does this statment mean ??? ("\n%-15s%11i", and how does it work in my program and why??

AS PART OF MY PROGRAM:

("\n%-15s%11i", "Account Number", Laccnum);
("\n%-15s%11i", "Number of Weeks", Lnwks);
("\n%-15s%11c", "T.V Type", Ltvtype);
("\n%-15s%11.2f", "Rent per week", Lrpw);
("\n%-15s%11.2f", "Total owing", Ltotbill);


Thanks again everyone, us begginers wouldnt get to far without the experts.

This topic is closed to new replies.

Advertisement