THESE FORUMS NOW CLOSED (read only)

  • 27 Apr 2024, 16:22
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: C++  (Read 3148 times)

Dissy

  • The German Chancellory building
  • ***
  • Offline Offline
  • Posts: 459
  • The only asshole in the internets
C++
« on: 11 Jun 2008, 11:43 »

I'm guessing that since this is computer related......


Source code:
# include <iostream>
# include <iomanip>
# include <fstream>
using namespace std;

//istream& getData(fstream &is, string name, int rate, int hours, int taxBracket,
//                         double ytd, double ytdTax, int week1);

//void calcGross(double rate, double hrs, double &gross);
//void calcTax(double grossPay, int taxBracket, double&tax);
int main()
{
    ifstream fin("lab4.in");
    if(fin.fail())
    {
                  cerr << "Error opening input file. \n\n";
                  exit(1);
    }
    ofstream fout("lab4.out");
    if(fout.fail())
    {
              cerr << "Error opening output file.\n\n";
              exit(1);
    }   
    fout.setf(ios::showpoint);
    fout.setf(ios::fixed);
    fout.precision(2);             
 
    double hours, pay, dependents, grosspay, overtime;
    double tax, taxpay, percent, finalpay;
    int workers;
   
    fin >> workers >> hours >> pay >> dependents >> tax;
   
    fout << "Lab 4\t\t\t Kevin \n";
    fout << setw(10) << "Employee\t" << setw(15) << "Hours worked\t"
         << setw(10) << "Pay Rate\t" << setw(15) << "Tax Bracket\t"
         << setw(5) << "# Dep\t" << setw(10) << "Gross Pay\t"
         << setw(15) << "Federal Tax\t" << setw(10) << "Net Pay\n";
    cout << "I'm bored.  What about you?\n"
         << "Seriously, why are you here?\n"
         << "Press Ctrl & C.\n" << endl;

    while (!fin.fail())
    {         
         if (hours > 40)
         {
            overtime = hours - 40;
            hours = 40;
         }
         if (tax==1)
            percent = .13;
         else if (tax==2)
            percent = .27;
         else if (tax==3)
            percent = .35;
         else percent = .35;
             percent = percent - (dependents*0.01);
             grosspay = (hours * pay) + (overtime * pay * 1.5);
             taxpay = grosspay * percent;
             finalpay = grosspay - taxpay;
             hours += overtime;
         
          fout << workers << "\t"
               << setprecision(2) << hours << "\t"
               << setprecision(2) << pay << "\t"
               << setprecision(2) << tax << "\t"
               << setprecision(2) << dependents << "\t"
               << setprecision(2) << grosspay << "\t"
               << setprecision(2) << taxpay << "\t"
               << setprecision(2) << finalpay << endl;
    }
    fin.close();
    fout.close();
    system ("pause");
    return 0;
}


File In:
  1         50.00      20.00        2         3   
2         40.00      10.00        1         0   
3         10.00      40.00        3         5   
4         40.00      11.25        1         2   



I am getting an infinite loop off of the first line.  Anyideas how to fix this?
Logged
Quote from: Tommy on Gabbly
i'm not paying for your boob jon
Quote from: Darryl
I fuck at typos
Quote from: Squiddy
but you haven't sig quoted me yet kevin
Quote from: Darryl on meebo
9 inches is pathetic by today's standard

morbid79

  • Obscure cultural reference
  • **
  • Offline Offline
  • Posts: 143
  • I like to work.
    • laccetti
Re: C++
« Reply #1 on: 11 Jun 2008, 12:49 »

My hack:

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

//istream& getData(fstream &is, string name, int rate, int hours, int taxBracket,
//                         double ytd, double ytdTax, int week1);

//void calcGross(double rate, double hrs, double &gross);
//void calcTax(double grossPay, int taxBracket, double&tax);
int main()
{
   ifstream fin("lab4.in");
   if(fin.fail())
   {
      cerr << "Error opening input file. \n\n";
      exit(1);
   }
   ofstream fout("lab4.out");
   if(fout.fail())
   {
      cerr << "Error opening output file.\n\n";
      exit(1);
   }   
   fout.setf(ios::showpoint);
   fout.setf(ios::fixed);
   fout.precision(2);             

   // Dump the header
   fout << "Lab 4\t\t\t Kevin \n";
   fout << setw(10) << "Employee\t" << setw(15) << "Hours worked\t"
         << setw(10) << "Pay Rate\t" << setw(15) << "Tax Bracket\t"
         << setw(5) << "# Dep\t" << setw(10) << "Gross Pay\t"
         << setw(15) << "Federal Tax\t" << setw(10) << "Net Pay\n";

   double hours, pay, dependents, grosspay, overtime;
   double tax, taxpay, percent, finalpay;
   int workers;

   while ((fin >> workers >> hours >> pay >> dependents >> tax) && !fin.fail())
   {
      if (hours > 40)
      {
         overtime = hours - 40;
         hours = 40;
      }
      if (tax==1)
         percent = .13;
      else if (tax==2)
         percent = .27;
      else if (tax==3)
         percent = .35;
      else percent = .35;
      percent = percent - (dependents*0.01);
      grosspay = (hours * pay) + (overtime * pay * 1.5);
      taxpay = grosspay * percent;
      finalpay = grosspay - taxpay;
      hours += overtime;

      fout << workers << "\t"
         << setprecision(2) << hours << "\t"
         << setprecision(2) << pay << "\t"
         << setprecision(2) << tax << "\t"
         << setprecision(2) << dependents << "\t"
         << setprecision(2) << grosspay << "\t"
         << setprecision(2) << taxpay << "\t"
         << setprecision(2) << finalpay << endl;
   }
   fin.close();
   fout.close();
   system ("pause");
   return 0;
}
Logged
King Lemon

Melodic

  • Only pretending to work
  • *****
  • Offline Offline
  • Posts: 2,115
  • archive chin panties
Re: C++
« Reply #2 on: 11 Jun 2008, 13:52 »

using namespace std;

What version of C++ uses this syntax?
Logged
And if you played too hard it'd flop out and dangle around by the wire and that is just super ugly

morbid79

  • Obscure cultural reference
  • **
  • Offline Offline
  • Posts: 143
  • I like to work.
    • laccetti
Re: C++
« Reply #3 on: 11 Jun 2008, 14:09 »

Uh, any kind?  AFAIK it is part of the language.  Sure compiles under GCC and MSVC.
Logged
King Lemon

Dimmukane

  • Vulcan 3-D Chess Master
  • *****
  • Offline Offline
  • Posts: 3,683
  • juicer
Re: C++
« Reply #4 on: 11 Jun 2008, 19:15 »

Yeah, it's a VERY common thing in VC++ projects....

Not to doubt your abilities as a programmer (I'm not), but how did you never come across that?
Logged
Quote from: Johnny C
all clothes reflect identity constructs, destroy these constructs by shedding your clothes and sending pictures of the process to the e-mail address linked under my avatar

Melodic

  • Only pretending to work
  • *****
  • Offline Offline
  • Posts: 2,115
  • archive chin panties
Re: C++
« Reply #5 on: 11 Jun 2008, 21:43 »

I only spent a short time on early builds of C++, when they updated the base every three weeks. I don't remember much, but we could totally start a Dev thread and I'd be all over it like white on rice.
Logged
And if you played too hard it'd flop out and dangle around by the wire and that is just super ugly

GenericName

  • Pneumatic ratchet pants
  • ***
  • Offline Offline
  • Posts: 335
  • Noooooooo
    • DeviantART
Re: C++
« Reply #6 on: 12 Jun 2008, 11:38 »

From what I remember, some programs do away with it because they figure most people are going to type that anyways so why not do it automatically?

But that was a year ago and I've forgotten all my C++, or else I'd help you with this.
Logged
Sometimes I see a terrible post so I click and look back at every post that person has ever made. That is why I never have time to actually post things.

Melodic

  • Only pretending to work
  • *****
  • Offline Offline
  • Posts: 2,115
  • archive chin panties
Re: C++
« Reply #7 on: 12 Jun 2008, 14:50 »

I think it was VC++ 6 or so that they did away with namespace syntax. I never realized they had added it back in until now.
Logged
And if you played too hard it'd flop out and dangle around by the wire and that is just super ugly

Catfish_Man

  • Pneumatic ratchet pants
  • ***
  • Offline Offline
  • Posts: 369
    • Assorted Stuff
Re: C++
« Reply #8 on: 19 Jun 2008, 23:24 »

using is definitely a part of standard C++, as are namespaces.

<edit>
Why are you testing against ios::fail()? ios::eof() seems like it's what you want (although I admit I didn't read your code very carefully
</edit>
« Last Edit: 19 Jun 2008, 23:26 by Catfish_Man »
Logged

Melodic

  • Only pretending to work
  • *****
  • Offline Offline
  • Posts: 2,115
  • archive chin panties
Re: C++
« Reply #9 on: 19 Jun 2008, 23:30 »

I never realized they added it in after it was removed from ~VC6. That's handy.

Also, on a similarly-brief glance I agree with on on eof.
Logged
And if you played too hard it'd flop out and dangle around by the wire and that is just super ugly
Pages: [1]   Go Up