我想在同一行询问学号和标记。
用户输入学号。如果它是有效的,那么它应该向右移动几个空格并允许用户输入标记。
目前它将进入下一行输入我的标记。
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
int counter;
int marks[40];
float num_grades = 0;
int row = 1;
float sum = 0;
float average = 0;
float pass_average = 0;
float fail_average = 0;
int array_pos = 0;
int fail = 0;
int pass = 0;
float pass_sum = 0;
float fail_sum = 0;
float biggest = 0;
float smallest = 0;
//int grade[40];
int student_num[40];
printf(" ---=== IPC mark Analyser V2.0 ===---\n");
printf("Please enter the number of students(between 3 and 40): ");
scanf("%d", &counter);
while (counter > 40 || counter < 3)
{
printf("Invalid number, enter a number between 3 and 40 inclusive: ");
scanf("%d", &counter);
}
printf("Row Std No Mrk\n");
printf("--- --------- ---\n");
num_grades = counter;
while (counter > 0)
{
printf("%d ", row);
printf("___________ ___\r%3d ", row);
scanf("%d", &student_num[array_pos]);
while (student_num[array_pos] < 10000000 || student_num[array_pos] > 999999999)
{
printf("Error: Enter student number values between 10000000 and 999999999 inclusive.\n");
printf("%d ", row);
printf("___________ ___\r%3d ", row);
scanf("%d", &student_num[array_pos]);
}
scanf("%d", &marks[array_pos]);
//printf("\r%3d %09d ___ ", row, student_num[array_pos]);
//scanf("%d", &marks[array_pos]);
while (marks[array_pos] < 0 || marks[array_pos] > 100)
{
printf("Error: Enter mark values between 0 and 100 inclusive.\n");
printf("\r%3d %09d ___ ", row, student_num[array_pos]);
scanf("%d", &marks[array_pos]);
}
if (num_grades == counter)
{
smallest = marks[array_pos];
biggest = marks[array_pos];
}
if (marks[array_pos] >= 50)
{
pass++;
pass_sum += marks[array_pos];
}
else if (marks[array_pos] < 50)
{
fail++;
fail_sum += marks[array_pos];
}
if (marks[array_pos] > biggest)
{
biggest = marks[array_pos];
}
if (marks[array_pos] < smallest)
{
smallest = marks[array_pos];
}
row++;
counter--;
sum += marks[array_pos];
array_pos++;
}
printf("=================\n");
printf("Marks Entered, printing results:\n");
printf("Row Std No Mrk\n");
printf("--- --------- ---\n");
int i;
for (i = 0; i < num_grades; i++)
{
printf("%03d %09d %3d ", i + 1, student_num[i], marks[i]);
if (marks[i] == biggest) {
printf("***Highest Mark***");
}
if (marks[i] == smallest) {
printf("***Lowest Mark***");
}
printf("\n");
}
average = sum / num_grades;
pass_average = pass_sum / pass;
fail_average = fail_sum / fail;
printf("===================\n");
printf("Total of %d students passed with an average of %.1f.\n", pass, pass_average);
printf("Total of %d students failed with an average of %.1f.\n", fail, fail_average);
printf("Highest mark in group: %.0f\n", biggest);
printf("Lowest mark in group: %.0f\n", smallest);
printf("The average of all marks in this group is %.1f.\n", average);
printf("Program Ended.\n");
return 0;
}