Need homework help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 43
Reputation: davids2004 is an unknown quantity at this point 
Solved Threads: 0
davids2004 davids2004 is offline Offline
Light Poster

Re: Need homework help

 
0
  #11
Nov 19th, 2008
Originally Posted by Rashakil Fol View Post
If you think your code produces the correct results on the inputs you've tried, maybe you could say what your code does to us, step by step. We could then see where you have a mistaken understanding.
Maybe I am not understanding what you are asking, but this is what my code does right now.

It ask for the number of days worked this month, as long as it is in between 1-31
then it takes the days I put in and first multiplies (0.01*2)*#days I put in and produces a result based off the days I have put in.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,047
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Need homework help

 
4
  #12
Nov 19th, 2008
But that wouldn't give the right result. It would give 0.50 if the number of days was 25. But on the 25th day, the person would earn 167772.16.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 43
Reputation: davids2004 is an unknown quantity at this point 
Solved Threads: 0
davids2004 davids2004 is offline Offline
Light Poster

Re: Need homework help

 
0
  #13
Nov 19th, 2008
Originally Posted by Rashakil Fol View Post
But that wouldn't give the right result. It would give 0.50 if the number of days was 25. But on the 25th day, the person would earn 167772.16.
Ok yes I know it is not producing the right result. That is my problem as how do I get the code to produce the right result.

I believe I need to set something to 0 and have it double each day they work, but I just do not get it.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: Need homework help

 
0
  #14
Nov 19th, 2008
If you set something to 0 you can double it for a lifetime - it will never become something different than 0.

Think on using a loop to add the dailySalary to the total earntMoney for each day of work. Then you can adjust the value of dailySalary to be added in every cycle of the loop at your pleasure
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,819
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Need homework help

 
0
  #15
Nov 19th, 2008
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. int days = 1;
  9. double firstDayPay=0.01;
  10. double salary=1,
  11. dailyPay=firstDayPay;
  12.  
  13.  
  14. cout << "How many days did you work?: ";
  15. cin >> days;
  16. while (days <1 || days>31)
  17. {cout << "That is an invalid days selection, please select 1-31: ";
  18. cin >> days;}
  19. salary = (firstDayPay * 2) * days;
  20. dailyPay = salary;
  21.  
  22.  
  23. cout << "\nPer day Total";
  24. cout << "\n-----------------------------\n";
  25.  
  26. cout << "Your total salary is: " << fixed << setprecision (2) << salary;
  27. cout << "\n";
  28.  
  29.  
  30.  
  31. return 0;
  32.  
  33. }

You need a loop, right? You have a loop, but only to get good input. Once you have good input, say 10, then you need to do something ten times, right?

should display a table showing how much the salary was for each day worked
That is one cout statement for every day. Right now you only have a cout statement for the grand total:

  1. cout << "Your total salary is: " << fixed << setprecision (2) << salary;

Where is the the cout statement for the individual days?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 43
Reputation: davids2004 is an unknown quantity at this point 
Solved Threads: 0
davids2004 davids2004 is offline Offline
Light Poster

Re: Need homework help

 
0
  #16
Nov 20th, 2008
Ok I am just not getting it at all.

I had programming.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 43
Reputation: davids2004 is an unknown quantity at this point 
Solved Threads: 0
davids2004 davids2004 is offline Offline
Light Poster

Re: Need homework help

 
0
  #17
Nov 20th, 2008
Got it working now. I just subracted 0.01 from the total and it comes up with the correct amount. Would there be an easier way to do this?

Thanks.

  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. int days, firstday;
  9. double numPay = .01;
  10. double total = 0;
  11.  
  12.  
  13.  
  14. cout << "How many days did you work?: ";
  15. cin >> days;
  16. cout <<"\n";
  17. while (days <1 || days>31)
  18. {cout << "That is an invalid days selection, please select 1-31: ";
  19. cin >> days;}
  20. firstday=1;
  21.  
  22. cout<<"Day"<<"\t\t"<<"Amount Earned"<<endl;
  23. cout<<"----------------------------"<<endl;
  24.  
  25. while (firstday<=days)
  26. {cout<< firstday <<"\t\t\t"<< numPay <<endl;
  27. numPay = numPay *2;
  28. firstday++;
  29. }
  30. total=numPay-0.01;
  31. cout<<" "<<endl;
  32. cout<< fixed << showpoint << setprecision(2);
  33. cout<<" Total Amount To Be Paid Is $"<<"\t"<< total << endl;
  34. cout<<" "<<endl;
  35. return 0;
  36. }
Last edited by davids2004; Nov 20th, 2008 at 11:12 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Need homework help

 
0
  #18
Nov 20th, 2008
How about this
  1. //...With original code
  2. salary = (dailyPay*days)*2;
  3. //...
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,819
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Need homework help

 
0
  #19
Nov 20th, 2008
Originally Posted by davids2004 View Post
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. int days, firstday;
  9. double numPay = .01;
  10. double total = 0;
  11.  
  12.  
  13.  
  14. cout << "How many days did you work?: ";
  15. cin >> days;
  16. cout <<"\n";
  17. while (days <1 || days>31)
  18. {cout << "That is an invalid days selection, please select 1-31: ";
  19. cin >> days;}
  20. firstday=1;
  21.  
  22. cout<<"Day"<<"\t\t"<<"Amount Earned"<<endl;
  23. cout<<"----------------------------"<<endl;
  24.  
  25. while (firstday<=days)
  26. {cout<< firstday <<"\t\t\t"<< numPay <<endl;
  27. numPay = numPay *2;
  28. firstday++;
  29. }
  30. total=numPay-0.01;
  31. cout<<" "<<endl;
  32. cout<< fixed << showpoint << setprecision(2);
  33. cout<<" Total Amount To Be Paid Is $"<<"\t"<< total << endl;
  34. cout<<" "<<endl;
  35. return 0;
  36. }
I would go through this code and rename a lot of the variables. The computer couldn't care less, but anyone reading it and trying to understand the code (including yourself) is going to get pretty confused because the variable names aren't a good description of what they represent.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC