Calculate the total amount of money earned in n days C++ code sample
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: To calculate the total amount of money earned in n days in C++ programming
To show: How to use the variables, operators, operands and data types in C++ programming
// calculate the total amount of money earned in n days
#include <iostream>
using namespace std;
int main(void)
{
int n;
int total, rate= 20;
cout<<"Enter number of days worked: ";
cin>>n;
total = n * rate;
cout<<"\n----------------------------";
cout<<"\n| For USD20 per day |";
cout<<"\n----------------------------";
cout<<"\n";
cout<<"\nFor "<<n<<" days of work, you have earned USD ";
cout<<total<<endl;
return 0;
}
Output example:
Enter number of days worked: 7
----------------------------
| For USD20 per day |
----------------------------
For 7 days of work, you have earned USD 140
Press any key to continue . . .