943,903 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1350
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 19th, 2008
0

Re: Need homework help

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
davids2004 is offline Offline
43 posts
since Nov 2008
Nov 19th, 2008
4

Re: Need homework help

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.
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
Nov 19th, 2008
0

Re: Need homework help

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
davids2004 is offline Offline
43 posts
since Nov 2008
Nov 19th, 2008
0

Re: Need homework help

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
Reputation Points: 134
Solved Threads: 18
Junior Poster
mrboolf is offline Offline
182 posts
since Jun 2008
Nov 19th, 2008
0

Re: Need homework help

C++ Syntax (Toggle Plain Text)
  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?

Quote ...
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:

C++ Syntax (Toggle Plain Text)
  1. cout << "Your total salary is: " << fixed << setprecision (2) << salary;

Where is the the cout statement for the individual days?
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Nov 20th, 2008
0

Re: Need homework help

Ok I am just not getting it at all.

I had programming.
Reputation Points: 10
Solved Threads: 0
Light Poster
davids2004 is offline Offline
43 posts
since Nov 2008
Nov 20th, 2008
0

Re: Need homework help

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.

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Light Poster
davids2004 is offline Offline
43 posts
since Nov 2008
Nov 20th, 2008
0

Re: Need homework help

How about this
c++ Syntax (Toggle Plain Text)
  1. //...With original code
  2. salary = (dailyPay*days)*2;
  3. //...
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Nov 20th, 2008
0

Re: Need homework help

Click to Expand / Collapse  Quote originally posted by davids2004 ...
C++ Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: isdigit ç à è
Next Thread in C++ Forum Timeline: memory game





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC