View Full Version : need more C++ help
greg123
Sep 21st, 2006, 09:44 AM
iam going through the unit walkthroughs on
http://cs.senecac.on.ca/~ipc144/ipcweb_html/unit4.html
on one excersise about looping it says
Copy and paste all the lines of code (do not copy the line numbers) into your compiler and try running the program. To avoid copying the line numbers, put your mouse on the # symbol in line one to begin highlighting.
#include
main()
{
double price, balance = 0.0;
while (balance < 5000.0)
{
printf("What is the purchase price?");
scanf ("%lf", &price) ;
balance = balance + price;
}
printf("You are over your credit limit with a
balance of %.2f\n", balance);
}
now when i copy and paste the codes into Borland C++ it comes up with errors
Info :Compiling C:\BC5\BIN\sadfs.CPP
Error: sadfs.CPP(11,19):Unterminated string or character constant
Error: sadfs.CPP(12,27):Function call missing )
Error: sadfs.CPP(12,35):Illegal character '\' (0x5c)
Error: sadfs.CPP(12,38):Unterminated string or character constant
Error: sadfs.CPP(13,2):Statement missing ;
Error: sadfs.CPP(13,1):Compound statement missing }
whats wrong here? iam entering the codes exactly like its showed on the excersise?
thx for the help
spm24
Sep 21st, 2006, 09:47 AM
wat page is the exercise you are doing ?
seems like your #include needs more so it has libraries to referfence to .
try doing
#include
#include
greg123
Sep 21st, 2006, 09:48 AM
wat page is the excerise you are doing ?
Exercise 4.1 just click next until it gets to 4.1
if there are better sites to learn C++ pleaser list them :|
i still dont get why this line is always first line of the program
#include
in the walkthrough it just says its include the standard input/output library
spm24
Sep 21st, 2006, 09:53 AM
i am rusty at this as i only did up to prg 255 at seneca
but the excersie says to use
#include
main()
{
double price, balance = 0.0;
while (balance < 5000.0)
{
printf("What is the purchase price?");
scanf ("%lf", &price) ;
balance = balance + price;
}
printf("You are over your credit limit with a
balance of %.2f\n", balance);
}
you were missing the STDio.H if i recall right all my old programs had that and conio.h as well.
try compiling the program exactly how i did it and it should work .
period3
Sep 21st, 2006, 10:01 AM
Just make the first line #include instead of just #include
#include tells the compiler to "include" another file - in this case the one with the prototypes for printf and scanf.
#include
main()
{
double price, balance = 0.0;
while (balance < 5000.0)
{
printf("What is the purchase price?");
scanf ("%lf", &price) ;
balance = balance + price;
}
printf("You are over your credit limit with a
balance of %.2f\n", balance);
} [/B]
now when i copy and paste the codes into Borland C++ it comes up with errors
Info :Compiling C:\BC5\BIN\sadfs.CPP
Error: sadfs.CPP(11,19):Unterminated string or character constant
Error: sadfs.CPP(12,27):Function call missing )
Error: sadfs.CPP(12,35):Illegal character '\' (0x5c)
Error: sadfs.CPP(12,38):Unterminated string or character constant
Error: sadfs.CPP(13,2):Statement missing ;
Error: sadfs.CPP(13,1):Compound statement missing }
whats wrong here? iam entering the codes exactly like its showed on the excersise?
thx for the help[/QUOTE]
spm24
Sep 21st, 2006, 10:08 AM
try using another compiler like TClite i am sure seneca has it on there computers still
each line of error will point to that line .
it also says there is a "/" somewhere where it shouldnt be. i dont got a compiler here but try doing what i previous stated. if the errors continue load up tclite ( if on the computers) and it should help ya out in which line has the error.
gman
Sep 21st, 2006, 10:10 AM
He probably included the right stuff. It is this forum (RFD's forum) strips out the "less than" character, "greater than" character and the stuff in between. It thinks it is a html tag.
gman
Sep 21st, 2006, 10:12 AM
iam going through the unit walkthroughs on
http://cs.senecac.on.ca/~ipc144/ipcweb_html/unit4.html
on one excersise about looping it says
Copy and paste all the lines of code (do not copy the line numbers) into your compiler and try running the program. To avoid copying the line numbers, put your mouse on the # symbol in line one to begin highlighting.
#include
main()
{
double price, balance = 0.0;
while (balance < 5000.0)
{
printf("What is the purchase price?");
scanf ("%lf", &price) ;
balance = balance + price;
}
printf("You are over your credit limit with a
balance of %.2f\n", balance);
}
now when i copy and paste the codes into Borland C++ it comes up with errors
Info :Compiling C:\BC5\BIN\sadfs.CPP
Error: sadfs.CPP(11,19):Unterminated string or character constant
Error: sadfs.CPP(12,27):Function call missing )
Error: sadfs.CPP(12,35):Illegal character '\' (0x5c)
Error: sadfs.CPP(12,38):Unterminated string or character constant
Error: sadfs.CPP(13,2):Statement missing ;
Error: sadfs.CPP(13,1):Compound statement missing }
whats wrong here? iam entering the codes exactly like its showed on the excersise?
thx for the help
You put this into 2 lines.
printf("You are over your credit limit with a
balance of %.2f\n", balance);
Concate the lines in to one or
printf("You are over your credit limit with a"
"balance of %.2f\n", balance)
if you have to use 2 lines. Note: there is no "," between "You are over your credit limit with a" and "balance of %.2f\n".
mrG
Sep 21st, 2006, 10:59 AM
Yeah, the last guy is right.
The problem is this line:
printf("You are over your credit limit with a
balance of %.2f\n", balance);
which can either be this:
printf("You are over your credit limit with a "
"balance of %.2f\n", balance);
or this
printf("You are over your credit limit with a \
balance of %.2f\n", balance);
or this
printf("You are over your credit limit with a balance of %.2f\n", balance);
NLI10D
Sep 22nd, 2006, 12:13 AM
do not use TClite. stay with Phobos and NLED. I made the mistake of doing that before and it would compile find and dandy but i got skewed results.
greg123
Sep 22nd, 2006, 02:58 PM
now it works thx for all the help....
are all compliers out there the same or which one do you guys recommand?
greg123
Sep 22nd, 2006, 03:12 PM
:confused:
supernerd
Sep 22nd, 2006, 05:28 PM
are all compliers out there the same or which one do you guys recommand?
No. Not all compilers are the same. Not even close. From a functional standpoint they're not even the same. There's little issues/bugs/caveats with all compilers, even with the "industrial" ones.
Which compiler you choose primarily depends on your platform. For home PC usage (i.e. x86 on windows or linux): gcc, MSVC (not on linux), and Intel are the main compilers that most people use...
mau108
Sep 22nd, 2006, 06:59 PM
#include
using namespace std;
main()
{
double price, balance = 0.0;
while (balance < 5000.0)
{
printf("What is the purchase price?");
scanf ("%lf", &price) ;
balance = balance + price;
}
printf("You are over your credit limit with a balance of %.2f\n", balance);
}
should work.... damn forum not letting me put iostream or stdio.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.