Re: newbie help.
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 11/25/03
- Next message: osmium: "Re: Beginners help"
- Previous message: André Pönitz: "Re: newbie help."
- In reply to: lightning_b0lt: "newbie help."
- Next in thread: lightning_b0lt: "Re: newbie help."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 26 Nov 2003 00:47:28 +1100
"lightning_b0lt" <lightning1974(removeme)@hotmail.com> wrote in message
news:bpvjkq$oil$1@sparta.btinternet.com...
| ive only just started learning C++ ..
| and was trying to sort out a little problem.
| basically i need help in making this program loop 5 times each time
| calculating the added increase.
| i dont want it written for me ,,,just some guidance on what im doing or not
| doing right !!!
| thank you for you pateince.
|
| #include <iostream.h>
Use <iostream> // Note, in C++ we do not usually use '.h'
// on the end of headers. If we use 'C'
// headers, then we add a lower case 'c'
// in front of it: # include <cstdlib>
| #include <iomanip.h>
Same here <iomanip>
- if you are actually going to make use of it later.
| #include <math.h>
You don't seem to be making use of this either, however
if you were, it would become <cmath> under 'C++'.
| int main()
Excellent :-).
| { float salary,annual,increase;
It is a good idea to initialise your variables
to zero when you declare them, and additionally
declare them on one line each for clarity.
Having said that, you should prefer to use the
'double' data type, rather than the 'float' type.
A 'double' has much better precision qualities
that what a 'float' can accomodate.
| cout <<"\n\nEnter your annual salary:\n\n";
| cin >>salary;
| cout <<"\n\nEnter your annual increase:\n\n";
| cin >>annual;
| if(salary,annual<0)
if( salary < 0 || annual < 0 )
| cout <<"\n\nNegative values are not allowed\n\n";
| else
| increase = salary + annual;
| cout <<"\n You salary is "<<increase<<endl;
| return 0;
| }
I don't like the use of too many new lines, particulary
with 'std::cin'. You may have to clear the stream buffer,
that is: extract the new lines before performing another
read. I would suggest looking up the istream::ignore()
member, and even istream::clear() - you will learn to use
these in combination with each other in good time :-).
Cheers.
Chris Val
- Next message: osmium: "Re: Beginners help"
- Previous message: André Pönitz: "Re: newbie help."
- In reply to: lightning_b0lt: "newbie help."
- Next in thread: lightning_b0lt: "Re: newbie help."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|