• 0

linking file stream with input file?


Question

ok i was given an assignment but i have no clue how to do this. can someone please explain to me what i'm supposed to do cause i'm really lost. this is the prompt.

The sales commission for each salesperson at Cars-Inc. is computed

based upon the following percentage of his/her total sales:

Total Sales (in US$) Commission

__________________________________________________ _

sale <= 35000 5%

35000 < sale <= 60000 7%

60000 < sale <= 90000 9%

90000 < sale 11%

Define the file stream *infile and link it to the given input file

"sales.dat" which is in the homework directory. Use

while(fgets()!=NULL) to read all the lines in "sales.dat". For odd

number lines (containing names) print the name on the screen. For

even number lines (with sales), sscanf &sale and calculate the

corresponding commission by using the above table; then print the sale

and the commission on the screen.

Finally, find the maximum value of the total sales. (You do not have to

print the name of the best sales person since you need pointers to save

the names.)

Note: Order the conditional expressions so that you do not have to use

the logical operators, || or &&. Specifically, if(35000<sale<=90000)

is incorrect since the expression consists of two conditional

expressions: 35000<sale and sale<=90000. The two expressions must be

joined by || or &&.

.................................................. .................

Your output on the screen should look like:

John Everhart

sales= 75900.00 commission= 6831.00

Paul Evans

sales= 95700.00 commission= 10527.00

...........

......................................

Steven King

sales= 68000.00 commission= 6120.00

Anne Rice

sales= 130000.00 commission= 14300.00

The maximum sales value is .....

i'm really lost at:

Define the file stream *infile and link it to the given input file

"sales.dat" which is in the homework directory. Use

while(fgets()!=NULL) to read all the lines in "sales.dat". For odd

number lines (containing names) print the name on the screen. For

even number lines (with sales), sscanf &sale and calculate the

corresponding commission by using the above table; then print the sale

and the commission on the screen. i opened the file sales.dat and this is what it was:

sales.dat

John Everhart

75900

Paul Evans

95700

Juan Hernandez

45100

Rwanda Jackson

88500

Steve Jhonson

35800

Henry Chen

105000

Tracy Ravad

56000

Scott Peters

98000

Alex Ma

89800

Alma Roberts

34500

Nelson Shah

33800

Steven King

68000

Anne Rice

130000

this is what i did (don't know if i'm doing it right):

#include <stdio.h>

main()

{

FILE *infile;

char text[81];

int count=0;

int tsales;

infile = fopen("sales.dat", "r");

if(infile == NULL){

exit(1);

}

while(fgets(text, 81, infile)!=NULL){

count++;

if(count%2 == 0){

sscanf(text, "%d", &tsales);

printf("tsales = $%d\n", tsales);

} else

printf("%s", text);

}

printf("There are %d lines.\n", count);

fclose(infile);

}

and when i compile and a.out it lists the data from sales.dat. but how would i get it to print the names in the odd lines and calculate commission for the even lines from the list?

Edited by flamehead144
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.