Need guidance for c program assignment

Status
Not open for further replies.

cprog26

Prominent
Aug 17, 2017
1
0
510
0
Hello, Everyone!!! I am fairly new to this forum, but nonetheless, need some guidance in regards to an assignment.

Here's the scoop, I need to write a program that totals the marks for each student for a course. At the end of each section, an average is to be printed. At the end of the program, a final average of all students’ grades is to be printed. When the program starts it will prompt the user for the Section Code (a number between 1 and 4 that identifies each unique class that are running concurrently in the semester). You must use a post-test loop to determine when the user has finished entering section codes.
The computer will then ask for the Student ID being marked (a 9 digit number entered without any special characters such as '-'). You must use a post-test loop to determine when the user has finished entering student IDs.
The computer will ask for the mark for each assignment for that student (there are 5 assignments; therefore there will be 5 prompts where each of the 5 marks are out of 20). You must use a pre-test loop to collect the 5 scores; you may not use 5 input statements in a row. The marks may contain decimal places, for example, 10.5 is a valid mark to enter.
When all 5 marks have been entered, the Student ID and the total of the 5 marks are displayed. The Student ID must be displayed as a 9 digit number, including leading zeroes if necessary.
A prompt for the next Student ID will be displayed. If the Student ID '0' is entered, the program will display the average for the class.
The computer will then prompt for the next Section Code.
The process will begin again by asking for Student IDs and marks. If the Section Code '0' is entered, the program will print the average of all of the student’s grades, and then stop.
When validating the input, if a value is out of range, include the correct range in the error message.


**This program is to be done with LOOPS only, and absolutely no IF statements**


What I have so far:

#include <stdio.h>
int main(void)
{
int sectionCode;
long studentID;
float knownMarks, total, averageMarks, percentageValue;


printf("\nEnter the Section Code: ");
scanf("%d", &sectionCode);

while(sectionCode != 0 && sectionCode > 5 );
{
printf("\nInvalid value entered. Must be 1 to 4");
printf(", please re-enter: ");
scanf("%d", &sectionCode);
}

printf("\nEnter the Student's ID: \n");
scanf("%ld", &studentID);

return 0;

}

As you can see it is at the beginning stage. My issue is when entering a number that is either supposed to be in range or not in range, the printf statement is executed.

Output:

Enter the Section Code: 0

Invalid value entered. Must be 1 to 4, please re-enter: 2

Enter the Student's ID:

252525
__________________________________________

Output:
Enter the Section Code: 3

Invalid value entered. Must be 1 to 4, please re-enter: 2

Enter the Student's ID:
252525

But when I re-enter the number within the statement, it proceeds to the next line of code.

What am I doing wrong? Guidance would be very appreciated! Thanks.
 

rgd1101

Titan
Moderator


There are 3(2 and a half)
the semi-colon
the sectionCode != 0 (relate to the &&)
the && (relate to the sectionCode != 0)
 

rgd1101

Titan
Moderator


There are 3(2 and a half)
the semi-colon
the sectionCode != 0 (relate to the &&)
the && (relate to the sectionCode != 0)
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
aymen9309 Apps General Discussion 1
SyndiShanX Apps General Discussion 1
D Apps General Discussion 1
BlueMoon1890 Apps General Discussion 0
Neon The (Anthro) Umbreon Apps General Discussion 1
K Apps General Discussion 2
T Apps General Discussion 10
M Apps General Discussion 2
R Apps General Discussion 3
S Apps General Discussion 2
N Apps General Discussion 1
P Apps General Discussion 4
A Apps General Discussion 8
M Apps General Discussion 6
S Apps General Discussion 1
convaallaria Apps General Discussion 5
H Apps General Discussion 3
A Apps General Discussion 1
U Apps General Discussion 5
D Apps General Discussion 2

ASK THE COMMUNITY