2 Replies - 4843 Views - Last Post: 31 August 2001 - 07:34 PM Rate Topic: -----

#1 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

infile input

Posted 31 August 2001 - 09:09 AM

ok, in my program i have infile support set up, but i cant get it to accept anything other than the first character names, like it accepts the name, then the social security number, but not the things like working hours. my infile is set up like this:

Rock N Roll
112-23-3445
56
August
31
Darth Raiders
010-10-1010
40
August
31
Oh Masterful One
aaa-bb-cccc
47.5
August
31
Whaz-up
224-46-6880
37.25
August
31

and my code is like this, please tell me if you know the problem(o yea, this code is just the infile part, i figure i wouldnt take up extra space on the board)

void infileinput()
{
infile.get(name,20);
infile.ignore(80,'
');
infile >> security;
infile.ignore(80,'
');
calculate();
}

void infilecalculate() { if(strcmp(name,"sloth")==0) { infile >> totalhours; infile.ignore(80,' '); if (totalhours>40.00) { overtimehours=totalhours-40.00f; hours=40.00f; state=0.060f; fed=0.220f; regularpayrate=5.55f; } else if ((totalhours<=40)&&(totalhours>0)) { overtimehours=0.00f; hours=totalhours; state=0.060f; fed=0.220f; regularpayrate=5.55f; }}

else if(strcmp(name,"Rock N Roll")==0)

{ infile >> totalhours; infile.ignore(80,' '); if (totalhours>40.00) { overtimehours=totalhours-40.00f; hours=40.00f; state=0.060f; fed=0.220f; regularpayrate=5.26f; } else if ((totalhours<=40)&&(totalhours>0)) { overtimehours=0.00f; hours=totalhours; state=0.060f; fed=0.220f; regularpayrate=5.26f; }}

else if(strcmp(name,"Darth Raiders")==0)

{ infile >> totalhours; infile.ignore(80,' '); if (totalhours>40.00) { overtimehours=totalhours-40.00f; hours=40.00f; state=0.004f; fed=0.075f; regularpayrate=28.00f; } else if ((totalhours<=40)&&(totalhours>0)) { overtimehours=0.00f; hours=totalhours; state=0.004f; fed=0.075f; regularpayrate=28.00f; }}

else if(strcmp(name,"Oh Masterful One")==0)

{ infile >> totalhours; infile.ignore(80,' '); if (totalhours>40.00) { overtimehours=totalhours-40.00f; hours=40.00f; state=0.800f; fed=0.030f; regularpayrate=13.78f; } else if ((totalhours<=40)&&(totalhours>0)) { overtimehours=0.00f; hours=totalhours; state=0.800f; fed=0.030f; regularpayrate=13.78f; }}

else if(strcmp(name,"Whaz-up")==0)

{ infile >> totalhours; infile.ignore(80,' '); if (totalhours>40.00) { overtimehours=totalhours-40.00f; hours=40.00f; state=0.888f; fed=0.094f; regularpayrate=16.66f; } else if ((totalhours<=40)&&(totalhours>0)) { overtimehours=0.00f; hours=totalhours; state=0.888f; fed=0.094f; regularpayrate=16.66f; }

else { cout << "sorry, hours are less than or equal to zero "; calculate(); }

} else { cout << "Username not found, please try again ";//if directions aren't followed input(); } cout << "Please enter the month it is"; infile.get(month,20); infile.ignore(80,' '); cout << "Please enter todays day number"; cin >> day; cin.ignore(80,' ');

overtime=regularpayrate*1.50f; overtimepay=overtime*overtimehours; regularpay=regularpayrate*hours; grosspay=regularpay+overtimepay; fedd=grosspay*fed; stated=grosspay*state; totald=stated+fedd; netpay=grosspay-totald;

open_outfile(); }

(Edited by supersloth at 10:29 am on Aug. 31, 2001)


Is This A Good Question/Topic? 0
  • +

Replies To: infile input

#2 runtime error  Icon User is offline

  • Lucky.Code
  • member icon

Reputation: 3
  • View blog
  • Posts: 629
  • Joined: 19-March 01

Re: infile input

Posted 31 August 2001 - 06:33 PM

You should retrieve all the information at one time. so put the rest of the infile>> things in the infileinput() function. Try it, if it doesn't work write back.
Was This Post Helpful? 0
  • +
  • -

#3 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,411
  • Joined: 21-March 01

Re: infile input

Posted 31 August 2001 - 07:34 PM

o yea, sorry, i got it  to work this afternoon in class, well part of it, whenever it loops around to the beginning of the programming, it wont read the next time. help on that would be much appreciated. o yea, the solution was that i was calling the wrong funcion. heh. but yea, i did what you said too, just to cut down on code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1