Computer Science Canada

Having percentage calculation problem

Author:  Quakerstate98 [ Mon Mar 24, 2008 1:44 pm ]
Post subject:  Having percentage calculation problem

I'm trying to build myself a budget program but my calculations for percent arnt working properly.

What i want is lets say u have a 400$ pay check
and u want to find out what 30% of that is and then put it into its own value
how would i go about doing so

Author:  michaelp [ Mon Mar 24, 2008 1:51 pm ]
Post subject:  RE:Having percentage calculation problem

You say your calculations aren't working? What do you mean?
And you would multiply the paycheck by 0.3 to get 30% of it.

Author:  syntax_error [ Mon Mar 24, 2008 1:55 pm ]
Post subject:  Re: Having percentage calculation problem

code:

double paycheck=400;
double balance =0;

balance =paycheck*0.3;

printf ("%.2d"+ balance);


?

Author:  Saad [ Mon Mar 24, 2008 2:01 pm ]
Post subject:  Re: Having percentage calculation problem

syntax_error wrote:

code:

double paycheck=400;
double balance =0;

balance =paycheck*0.3;

printf ("%.2d"+ balance);


?


Why are you using printf, printf is a C function to output items to a screen, you should be using std::cout since this is C++ not C.

Further more the code can be shortened a bit more to

c++:
double paycheck=400;
double balance = paycheck * 0.3;



Saad

Author:  syntax_error [ Mon Mar 24, 2008 2:26 pm ]
Post subject:  RE:Having percentage calculation problem

srry it was more of a prosudo code then a full solution

Author:  michaelp [ Mon Mar 24, 2008 3:30 pm ]
Post subject:  RE:Having percentage calculation problem

Those calculations should work, if they don't already.


: