Write a program that calculates how much a person would earn over a period of time if his or her salary is one ringgit the first day and two ringgit the second day, and continues to double each day. The program should ask the user for the number of days. Display how much the salary was for each day, and then show the total pay at the end of the period.

Recommended Answers

All 7 Replies

Do you have any code at all yet?

commented: #include <iostream> #include <iomanip> using namespace std ; void main () { int total_month; float total_salary = 0, total_pay = 0; c +0

This is a simple factoral problem. 1, 2, 4, 8, 16, 32, 64, 128...
As DaveAmour asks, do you have any code yet?

commented: #include <iostream> #include <iomanip> using namespace std ; void main () { int total_month; float total_salary = 0, total_pay = 0; c +0

you can also solve this problem by using switch statements incase if you are required to calculate salary for a week..

miazara: I see that you tried to reply to DaveAmour and rubberman, but you entered the code into the comments, which is too short for such purposes. You need to use the Reply box at the bottom of the page to send a full length reply.

# include <iostream>
# include <iomanip>

using namespace std;

void main() 

{


int year, total_year = 2500;
float total_year1 = total_year; 

for (year = 0 ; year <= 10  ; year++)

{


if (year >= 6)
   total_year1 = total_year + 0.04;


cout << " Total membership fee per-year : RM " << total_year1 << endl; 


}

}
#include <iostream>
#include <iomanip>
using namespace std ;


void  main ()
{

   int total_month;
   float total_salary = 0, total_pay = 0;

   cout << "Please enter total_salary : " ;
   cin >> total_salary ;


   for (total_month = 1; total_month <= 30 ; total_month++)

   {

   cout << " Total salary end of the month  :RM " << total_pay << endl;

   total_pay = (total_month * total_salary) + 1.00;

   }  
}

Can you explain, in detail, the problem you are having, or the part you aren't able to implement? I you are getting any error messages from the compiler, please post them as well.

As an aside, in C++ the main() function always is of type int, and has to have a return value of either zero or some error code. Always, without exception. While void main() was permissible in earlier versions of the C standard (in order to accomodate some non-standard operating systems), it has never been acceptable in C++, even pre-standard. Your compiler should at least be warning you about this, and the fact that it isn't is a sign that it isn't a standards-compliant compiler.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.