Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Having percentage calculation problem
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Quakerstate98




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
michaelp




PostPosted: 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.
syntax_error




PostPosted: 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);


?
Saad




PostPosted: 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
syntax_error




PostPosted: 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
michaelp




PostPosted: Mon Mar 24, 2008 3:30 pm   Post subject: RE:Having percentage calculation problem

Those calculations should work, if they don't already.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: