| | |
Need homework help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 43
Reputation:
Solved Threads: 0
Write a program that calculates how much a person earns in a month if the salary is one penny the first day and doubles each day worked. The program should ask the user for the number of days worked during the month and should display a table showing how much the salary was for each day worked, as well as the total pay earned for the month.
Input validation: Do not accept a number less than 1 or more than 31.
Here is my code so far as I am stumped on how to get the salary to double with each day. I believe you have to set something to =0*2 but not sure exactly what
The stuff in bold I have so far in the above description.
[CODE]
Input validation: Do not accept a number less than 1 or more than 31.
Here is my code so far as I am stumped on how to get the salary to double with each day. I believe you have to set something to =0*2 but not sure exactly what
The stuff in bold I have so far in the above description.
[CODE]
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <iomanip> using namespace std; int main () { int days; double salary; double const dailyPay=0.01; cout << "How many days did you work?: "; cin >> days; while (days <1 || days>31) {cout << "That is an invalid days selection, please select 1-31: "; cin >> days;} salary = (dailyPay * 2) * days; cout << "\nPer day Total"; cout << "\n-----------------------------\n"; cout << "Your total salary is: " << fixed << setprecision (2) << salary; cout << "\n"; return 0; }
Last edited by davids2004; Nov 19th, 2008 at 1:42 am.
Initialize the salary at 1 and, each time through some look that runs 'days' times, double it.
Or you could just use
Or you could just use
1 << (n - 1) to compute the amount paid on the nth day, or (1 << n) - 1 will give you the cumulative amount paid after n days. All my posts may be redistributed under the GNU Free Documentation License.
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
Re: Need homework help:Double pay each day, total pay per day, total pay for month
1
#3 Nov 19th, 2008
•
•
•
•
Write a program that calculates how much a person earns in a month if the salary is one penny the first day and doubles each day worked. The program should ask the user for the number of days worked during the month and should display a table showing how much the salary was for each day worked, as well as the total pay earned for the month.
Input validation: Do not accept a number less than 1 or more than 31.
Here is my code so far as I am stumped on how to get the salary to double with each day. I believe you have to set something to =0*2 but not sure exactly what
The stuff in bold I have so far in the above description.
[CODE]C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <iomanip> using namespace std; int main () { int days; double salary; double const dailyPay=0.01; cout << "How many days did you work?: "; cin >> days; while (days <1 || days>31) {cout << "That is an invalid days selection, please select 1-31: "; cin >> days;} salary = (dailyPay * 2) * days; cout << "\nPer day Total"; cout << "\n-----------------------------\n"; cout << "Your total salary is: " << fixed << setprecision (2) << salary; cout << "\n"; return 0; }
dailyPay a constant? If dailyPay doubles each day, then it is changing and therefore should not be a constant. If you want to have a constant variable, create a variable called firstDayPay , make it constant, assign it to equal one penny, than assign dailyPay to firstDayPay . Then start doubling dailyPay . dailyPay needs to change each day. •
•
Join Date: Nov 2008
Posts: 43
Reputation:
Solved Threads: 0
Re: Need homework help:Double pay each day, total pay per day, total pay for month
0
#5 Nov 19th, 2008
•
•
•
•
Initialize the salary at 1 and, each time through some look that runs 'days' times, double it.
Or you could just use1 << (n - 1)to compute the amount paid on the nth day, or(1 << n) - 1will give you the cumulative amount paid after n days.
•
•
•
•
Line 10. Why isdailyPaya constant? IfdailyPaydoubles each day, then it is changing and therefore should not be a constant. If you want to have a constant variable, create a variable calledfirstDayPay, make it constant, assign it to equal one penny, than assigndailyPaytofirstDayPay. Then start doublingdailyPay.dailyPayneeds to change each day.
Thanks to both of you
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
Re: Need homework help:Double pay each day, total pay per day, total pay for month
0
#6 Nov 19th, 2008
•
•
Join Date: Nov 2008
Posts: 43
Reputation:
Solved Threads: 0
Re: Need homework help:Double pay each day, total pay per day, total pay for month
0
#7 Nov 19th, 2008
•
•
•
•
Yes. I left out a word: "assign dailyPay to equal firstDayPay"
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <iomanip> using namespace std; int main () { int days = 1; double firstDayPay=0.01; double salary=1, dailyPay=firstDayPay; cout << "How many days did you work?: "; cin >> days; while (days <1 || days>31) {cout << "That is an invalid days selection, please select 1-31: "; cin >> days;} salary = (firstDayPay * 2) * days; dailyPay = salary; cout << "\nPer day Total"; cout << "\n-----------------------------\n"; cout << "Your total salary is: " << fixed << setprecision (2) << salary; cout << "\n"; return 0; }
Last edited by davids2004; Nov 19th, 2008 at 2:21 am.
•
•
Join Date: Nov 2008
Posts: 43
Reputation:
Solved Threads: 0
Ok I do put in sample inputs and it comes out producing the correct result. It is basically multiplying .02 * the number of days I put in and out comes the correct amount. I am trying to get the dailyPay to double each day per day worked.
![]() |
Similar Threads
- We only give homework help to those who show effort (Computer Science)
- Need help with Computer Science homework (Computer Science)
- Dynamic memory allocation homework (C++)
- Homework Help!! Priority Queue ?? (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: isdigit ç à è
- Next Thread: memory game
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






