Re: newbie help.

From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 11/25/03


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



Relevant Pages

  • Re: Numeric rounding not working?
    ... The data type decimal holds zero digits after the decimal point, ... declare @lat1 as float ...
    (microsoft.public.sqlserver.programming)
  • Re: Floating point arithmetic support in DCL
    ... If A had been previously declared as float, ... > the data type of the value that is assigned to them. ... > assignment it should contain the value 1 and be of type integer. ... Consider this - introduce a new assignment mechanism to declare ...
    (comp.os.vms)
  • Re: sound synthesis
    ... > the declarations and using short float helped, ... (defun mix (target-samples source-samples start sample-rate) ... (declare (float sample-rate seconds) ... (defun fm-gong (time freq) ...
    (comp.lang.lisp)
  • Re: Extending T-SQL with COM
    ... Using Excel for this is an extremely heavy weight way of performing what ... declare @rate float ... > GRANT EXECUTE ON dbo.sp_hexadecimal TO Public ...
    (microsoft.public.sqlserver.programming)
  • Re: sharing information in a class
    ... Shape (int c, int r) ... void SetArea(float radius){ ... float GetArea(){return area;} ... // cin>> value; ...
    (comp.lang.cpp)