| | |
Need homework help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 43
Reputation:
Solved Threads: 0
•
•
•
•
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.
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.
•
•
Join Date: Nov 2008
Posts: 43
Reputation:
Solved Threads: 0
•
•
•
•
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.
I believe I need to set something to 0 and have it double each day they work, but I just do not get it.
•
•
Join Date: Jun 2008
Posts: 182
Reputation:
Solved Threads: 18
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
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
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
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; }
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
C++ Syntax (Toggle Plain Text)
cout << "Your total salary is: " << fixed << setprecision (2) << salary;
Where is the the cout statement for the individual days?
•
•
Join Date: Nov 2008
Posts: 43
Reputation:
Solved Threads: 0
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.
Thanks.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <iomanip> using namespace std; int main () { int days, firstday; double numPay = .01; double total = 0; cout << "How many days did you work?: "; cin >> days; cout <<"\n"; while (days <1 || days>31) {cout << "That is an invalid days selection, please select 1-31: "; cin >> days;} firstday=1; cout<<"Day"<<"\t\t"<<"Amount Earned"<<endl; cout<<"----------------------------"<<endl; while (firstday<=days) {cout<< firstday <<"\t\t\t"<< numPay <<endl; numPay = numPay *2; firstday++; } total=numPay-0.01; cout<<" "<<endl; cout<< fixed << showpoint << setprecision(2); cout<<" Total Amount To Be Paid Is $"<<"\t"<< total << endl; cout<<" "<<endl; return 0; }
Last edited by davids2004; Nov 20th, 2008 at 11:12 am.
How about this
c++ Syntax (Toggle Plain Text)
//...With original code salary = (dailyPay*days)*2; //...
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
•
•
•
•
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <iomanip> using namespace std; int main () { int days, firstday; double numPay = .01; double total = 0; cout << "How many days did you work?: "; cin >> days; cout <<"\n"; while (days <1 || days>31) {cout << "That is an invalid days selection, please select 1-31: "; cin >> days;} firstday=1; cout<<"Day"<<"\t\t"<<"Amount Earned"<<endl; cout<<"----------------------------"<<endl; while (firstday<=days) {cout<< firstday <<"\t\t\t"<< numPay <<endl; numPay = numPay *2; firstday++; } total=numPay-0.01; cout<<" "<<endl; cout<< fixed << showpoint << setprecision(2); cout<<" Total Amount To Be Paid Is $"<<"\t"<< total << endl; cout<<" "<<endl; return 0; }
![]() |
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 beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






