A worker takes a job for 5 days. His pay for the day 1 is Rs. X, for day 2 is Rs. 2X and so on. Develop a C++ program to find the total salary.
#include <iostream>
using namespace std;
int main()
{
// declare and initialize variables
double x, pay = 0.0;
int day;
cout << "Enter Pay for 1 day: ";
cin >> x;
for(day = 5; day > 0; day-- )
pay = pay + x*day;
cout << "Total salary for 5 days: " << pay <<" Rs."<<endl;
return 0;
}
Comments
Leave a comment