Monday, June 29, 2015

C programming / hourly wage prog

#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>
#define LWage (float) 8.15
#define MWage (float) 12.55
#define HWage (float) 18.60
void main()
{
   float Hours = 1;
   float Pay;
   float Rate;
   float Sum = 0.0;
   int SkillIndicator;
 cout << setprecision(2);
   cout << setiosflags(ios :: showpoint);
   cout << setiosflags(ios :: fixed); //Needed only for large numbers

   while(Hours > 0) //hours must have a starting value
   {
     cout << endl << endl << "Enter negative value to end or";
     cout << endl <<"Enter hours worked -> ";
     cin >> Hours;
     if (Hours >= 0)
     {
        cout << "Enter skill indicator (1,2,3) -> ";
        cin >> SkillIndicator;
       if (SkillIndicator == 1)
          Rate = HWage;
       else if (SkillIndicator == 2)
          Rate = MWage;
       else if (SkillIndicator == 3)
          Rate = LWage;
       else
          {
           cerr << "You entered an invalid skill indicator";
           continue;
          }













#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>
#include <ctype.h>
#define LWage (float) 8.15
#define MWage (float) 12.55
#define HWage (float) 18.60
void main()
{
   float Hours = 1;
   float Pay;
   float Rate;
   float Sum = 0.0;
   char SkillIndicator;
   cout << setprecision(2);
   cout << setiosflags(ios :: showpoint);
   cout << setiosflags(ios :: fixed); //Needed only for large numbers
do
   {
     cout << endl <<"Enter a negative value to end or";
     cout << endl <<"Enter hours worked -> ";
     cin >> Hours;
     if (Hours > 0)
     {
        cout << endl << "Enter skill indicator (A,B,C) -> ";
        cin >> SkillIndicator;
        SkillIndicator = toupper(SkillIndicator); // toupper in ctype.h
        switch (SkillIndicator)
     {
         case 'A':
       Rate = HWage;
       break;
     case 'B':
       Rate = MWage;
       break;
     case 'C':
        Rate = LWage;
  break;
      default:
        cerr << endl << "You entered an invalid skill indicator";
        continue;
  }

        Pay = Rate * Hours;
        cout << "Worker's pay is $" << Pay << endl;
        Sum += Pay;
      }
  } while(Hours >= 0);
  cout << endl<<"Total workers daily pay is $" << Sum;
}

No comments:

Post a Comment