Home > Back-end >  There was a problem C language output
There was a problem C language output

Time:01-04

In the console output program error, input data from ten students finish the first line of input ready to enter the next line, but a press enter the program ended, please help solve it

CodePudding user response:

Only one line of input

CodePudding user response:

reference 1st floor space to the breeze full building response:
only one line of input

(????? ) I opened to, this code should be the branch information input ten students, as a result of the input a press enter is over

CodePudding user response:

Your source code?

CodePudding user response:

The scanf is getting out, your input and it does not match the demand, it is angry,

CodePudding user response:

reference 4 floor forever74 response:
the scanf is getting out, your input and it does not match the demand, it is angry,

What a guy, not the kui is your

CodePudding user response:

reference QZJHJXJ reply: 3/f
your source code?

#include
# define N number 10//students for 10
Struct Student//building structure type struct Student
{
int num;//student id
char name[20];//achievement
Float score [3].//3 course grades
Float aver.//average score
};
Int main ()
{
Void input (struct Student stu []);//function declaration
Struct Student Max (struct Student stu []);//function declaration
Void print (struct Student stu);//function declaration
Struct Student stu [N], * p=stu.//define structure array and pointer
Input (p);//input function called
Print (Max (p));//call the print function to Max function return values as arguments
return 0;
}
Void input (struct Student stu [])//define input function
{
int i;
Printf (" please input the student's information: student id, name, 3 course results: \ n ");
For (I=0; I & lt; N; I++)
{
Scanf_s (" % d % s % f % f % f ", & amp; Stu [I]. Num, & amp; Stu [I]. Name, & amp; Stu [I] score [0], & amp; Stu [I] score [1], & amp; Stu [I] score [2]);//input data
Stu [I] aver=(stu [I] score stu [0] + [I] score [1] + stu [I] score [2])/3.0; Average score//o

}
}
Struct Student Max (struct Student stu [])//define Max function
{
Int I, m=0;//m deposit scores the highest number of students in the array
For (I=0; I & lt; N; I++)
If (stu [I] aver & gt; Stu [m]. Aver)//find out the highest grade students in the serial number of the array
M=I;
Return stu [m];//return contains information about the student structure element
}
Void print (struct Student stud)//define the print function
{

CodePudding user response:

reference QZJHJXJ reply: 3/f
your source code?

This is the code # include
# define N number 10//students for 10
Struct Student//building structure type struct Student
{
int num;//student id
char name[20];//achievement
Float score [3].//3 course grades
Float aver.//average score
};
Int main ()
{
Void input (struct Student stu []);//function declaration
Struct Student Max (struct Student stu []);//function declaration
Void print (struct Student stu);//function declaration
Struct Student stu [N], * p=stu.//define structure array and pointer
Input (p);//input function called
Print (Max (p));//call the print function to Max function return values as arguments
return 0;
}
Void input (struct Student stu [])//define input function
{
int i;
Printf (" please input the student's information: student id, name, 3 course results: \ n ");
For (I=0; I & lt; N; I++)
{
Scanf_s (" % d % s % f % f % f ", & amp; Stu [I]. Num, & amp; Stu [I]. Name, & amp; Stu [I] score [0], & amp; Stu [I] score [1], & amp; Stu [I] score [2]);//input data
Stu [I] aver=(stu [I] score stu [0] + [I] score [1] + stu [I] score [2])/3.0; Average score//o

}
}
Struct Student Max (struct Student stu [])//define Max function
{
Int I, m=0;//m deposit scores the highest number of students in the array
For (I=0; I & lt; N; I++)
If (stu [I] aver & gt; Stu [m]. Aver)//find out the highest grade students in the serial number of the array
M=I;
Return stu [m];//return contains information about the student structure element
}
Void print (struct Student stud)//define the print function
{
Printf (" \ n scores the highest of the students are: \ n ");
Student id: printf (" % d \ n name: % s \ n three classes: % 5.1 f, % 5.1 f, average grade: % 5.1 f \ n \ n % 6.2 f ", stud, num, stud. The name, stud. Score [0], stud. Score [1], stud. Score [2], stud, aver);
}

CodePudding user response:

Said the problem of input is the light
Scanf_s (" % d % s % f % f % f ", & amp; Stu [I]. Num, stu [I]. Name, 19, & amp; Stu [I] score [0], & amp; Stu [I] score [1], & amp; Stu [I] score [2]);

Delete a & amp; , you know,
Added a 19, this is the suffix _s scanf_s extra small temper,

CodePudding user response:

To search the scanf_s () function usage, here under the input function changed, no trouble, for reference:
 
Void input (struct Student stu [])//define input function
{
int i;
Printf (" please input the student's information: student id, name, 3 course results: \ n ");
For (I=0; I & lt; N; I++)
{
The scanf (" % d % s % f % f % f ",
& Stu [I]. Num, & amp; Stu [I]. Name, & amp; Stu [I] score [0], & amp; Stu [I] score [1], & amp; Stu [I] score [2]);//input data
Stu [I] aver=(stu [I] score stu [0] + [I] score [1] + stu [I] score [2])/3.0; Average score//o
}
}

The running effect is as follows, chose three input:

CodePudding user response:

The scanf_s don't have space in brackets,
  • Related