Home > Back-end >  A c language program there is no error, but can't run it out
A c language program there is no error, but can't run it out

Time:09-22

# include
# include
# include Exit function called/* */
# include
# define M 155/* */a macro definition
Void the detail ();
Void foreach ();
Void menu ();
Void product ();
Void readdata ();
Void seller ();
Void total ();
Void choice ();
Struct ss
{
Int sid.//salesman code
Int pid;//product code
Int sn;//sales
} ss [M];
int n;//note number
Int s [4] [5]={,0,0,0,0 {0}, {0,0,0,0,0},,0,0,0,0 {0}, {0,0,0,0,0}};//used to hold employees and product information
Void main ()//entry function, namely the main function
{
Readdata ();//read the file data
The foreach ();//based on the initial data file is easy to operate the initialization array
The menu ();//display the main menu
}
Void readdata ()//the data read from the file
{
The FILE * fp.
If ((fp=fopen (" list. TXT ", "w"))==NULL)
{
Printf (" Can 't open the file! \n");
exit(0);
}
The else
For (n=0; ! The feof (fp); N++)
{
Fscanf (fp, "% d % d % d \ n", & amp; Ss [n]. Sid, & amp; Ss [n]. The pid, & amp; Ss [n]. Sn);
}//to save the file data structure
fclose(fp);
}
Void foreach ()//read the data from the note and sorting
{
int i;
for(i=0; i{
The switch (ss [I]. Pid)
//by product categories, according to the categories of salesman small classes, accumulate personal each product sales amount
{
Case 1:
The switch (ss [I]. Sid)
{
Case 1: s [0] [0] +=ss [I] sn. break;
Case 2: s [1] [0] +=ss [I] sn. break;
Case 3: s [2] [0] +=ss [I] sn. break;
Case 4: s [3] [0] +=ss [I] sn. break;
}
break;
Case 2:
The switch (ss [I]. Sid)
{
Case 1: s [0] [1] +=ss [I] sn. break;
Case 2: s [1] [1] +=ss [I] sn. break;
Case 3: s [2] [1] +=ss [I] sn. break;
Case 4: s [3] [1] +=ss [I] sn. break;
}
break;
Case 3:
The switch (ss [I]. Sid)
{
Case 1: s [0] [2] +=ss [I] sn. break;
Case 2: s [1] [2] +=ss [I] sn. break;
Case 3: s [2], [2] +=ss [I] sn. break;
Case 4: s [3] [2] +=ss [I] sn. break;
}
break;
Case 4:
The switch (ss [I]. Sid)
{
Case 1: s [0] [3] +=ss [I] sn. break;
Case 2: s [1] [3] +=ss [I] sn. break;
Case 3: s [2] [3] +=ss [I] sn. break;
Case 4: s [3] [3] +=ss [I] sn. break;
}
break;
Case 5:
The switch (ss [I]. Sid)
{
Case 1: s [0] [4] +=ss [I] sn. break;
Case 2: s [1] [4] +=ss [I] sn. break;
Case 3: s [2] [4] +=ss [I] sn. break;
Case 4: s [3] [4] +=ss [I] sn. break;
};
break;
}
}
}
Void menu ()
{
Int w, c;
Do {
Puts (" t \ \ t * * * * * * * * * * * * * * * * * * * * menu * * * * * * * * * * * * * * * * * * * * * \ n \ n ");
Puts (" t \ \ t 1. View the sales of each product in each \ n ");
Puts (" t \ \ t 2. According to the sales of salesman sort (salesman code) \ n ");
Puts (" t \ \ t 3. The total sales for each product (from high to low order (product code and sales) \ n ");
Puts (" t \ \ t 4. Output statistics \ n ");
Puts (" exit 5. T \ \ t \ n ");
Puts (" \ n \ n \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" please choose (1-5) : [] b \ \ b ");
The scanf (" % d ", & amp; c);
If (c<1 | | c> 5)//input error, to obtain input
{
W=1;
getchar();
}
The else w=0;
} while (w==1);

The switch (c)//according to the input to realize the corresponding function call
{
Case 1:
The detail (); break;//each salesman sales statistics of each product in
Case 2:
Seller (); break;
Case 3:
The product (s); break;
Case 4:
Total (); break;
Case 5:
exit(0);

}
}
Void the detail ()//show sales
{
Int I, j;
for(i=0; i<4. I++)//traverse salesman
{
Printf (" \ n \ t \ t % d salesman sales: \ n ", I + 1);
for(j=0; j<5; J++)
//classified by salesman traversal and display all products information
Printf (" \ t \ t % d product sales quantity: % d \ n ", j + 1, s [I] [j]);
}

Choice ();
}
Void seller ()
{
Int I, j, k;
Int sp [4]=,0,0,0 {0};
for(i=0; i<4. I++)
for(j=0; j<5; J++)
Sp +=s [I] [I] [j];
//calculate every single salesman all products sales quantity
for(i=0; i<4. I++)//compare four times, each time to select the top number
{k=0;//for marking maximum number of single wheel
for(j=0; j<4. J++)
If (sp [k] Printf (" t \ \ t is the first name % d % d salesman! \ n ", I + 1, k + 1); Sp [k]=1;
//output maximum number and ranking, the maximum number marked negative
}
Choice (); }
Void the product (s)//and the seller () principle, used for statistics on products is conducted by
{int I, j, k;
Int p=,0,0,0,0 {0} [5];
for(j=0; j<5; J++)
for(i=0; i<4. I++)
P=s [I] [j] + [j];
for(j=0; j<5; J++)
{k=0;
for(i=0; i<5; I++)
If (p [k] <[I]) k=p I;
Printf (" \ t \ t the first number is % d % d name! Sales \ t for % d! The \ n ", j + 1, k + 1, p (k)); P [k]=1; }
Choice ();
}
Void total ()//output report
{int I, j;
Printf (" \ n \ t salesman \ t products sales \ t \ n ");
for(i=0; i<4. I++)
for(j=0; j<5; J++)
Printf (" % d \ \ t t t % d % d \ \ n ", I + 1, j + 1, s [I] [j]);
Choice ();
}
Void choice ()//used to output information function to choose
{
int c;
Printf (" please select what want to do next \ t1 & gt; Return to the menu \ t2 & gt; Exit system [] b \ \ b ");
The scanf (" % d ", & amp; c);
If (c==1)
The menu ();
The else
exit(0);
Puts (" \ n ");
}

CodePudding user response:

For (n=0; ! The feof (fp); N++)
{
Fscanf (fp, "% d % d % d \ n", & amp; Ss [n]. Sid, & amp; Ss [n]. The pid, & amp; Ss [n]. Sn);
}//
There are problems

CodePudding user response:

Fscanf (fp, "% d % d % d", & amp; Ss [n]. Sid, & amp; Ss [n]. The pid, & amp; Ss [n]. Sn); Have a try

CodePudding user response:

 void choice ()//used to output information function to choose 
{
int c;
Printf (" please select what want to do next \ t1 & gt; Return to the menu \ t2 & gt; Exit system [] b \ \ b ");
nullnullnullnullnullnullnullnullnull
  • Related