Hey Guys.,
Im super desparate have 1 day to hand this in. Have to use loops only.

quote:
The use of any of the following C statements or functions is not permitted under any circumstances.
break;
continue;
exit();
abort();
No global variables.


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 for this loop.
The computer will then ask for the Student ID being marked (a 9 digit number entered without any special characters such as '-'). Again a post-test loop is to be used.
The computer will ask for the mark for each question of the exam for that student (there are 7 questions, therefore there will be 7 prompts where all 7 marks total 100 for a perfect score). You must use a pre-test loop to collect the 7 scores, you may not use 7 input statements in a row. The marks may contain decimal places, for example, 10.5 is a valid mark to enter.
When all 7 marks have been entered, the Student ID and the total of the 7 marks is 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 combined average of all the sections, then stop.
When validating the input, if a value is out of range, include the correct range in the error message. For example:

Enter the Section Code: 0

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

Enter the Student's ID: 456789

Enter mark#1: 10

Enter mark#2: -20

Invalid grade entered. Must be 0.0 to 100.0, please re-enter: 20

Enter mark#3: 5.5

Enter mark#4: 5

Enter mark#5: 10

Enter mark#6: 6

Enter mark#7: 7

000456789's total mark is: 63.5


Enter the Student's ID : 123654987

Enter mark#1: 1

Enter mark#2: 2

Enter mark#3: 3

Enter mark#4: 4

Enter mark#5: 5

Enter mark#6: 6

Enter mark#7: 7
123654987's total mark is: 28.0


Enter the Student's ID : 0

The average for the section is 45.75%


Enter the Section Code [0 to quit]: 5

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

Enter the Student's ID: 987654

Enter mark#1: 7

Enter mark#2: 6

Enter mark#3: 5

Enter mark#4: 4

Enter mark#5: 3

Enter mark#6: 2

Enter mark#7: 1

000987654's total mark is: 28.0


Enter the Student's ID : 0

The average for the section is 28.00%


Enter the Section Code [0 to quit]: 0


The average for the course is 39.83%

here comes my code:

#include<stdio.h>


int SecCode(int small_var);
long StudentId(int small_var);
double Mark(void);
void PrintIt(int std_num, double std_mark);

int get_int(void);

main()
{
	
	int section;
	int student_id;
	double mark;
	double std_aver;

	/*----------------*/
	
	double total_marks;	
	int total_students_counter=0;
	int section_counter=0;
	double studnt_section_aver;
        double course_aver;
	double master_aver;
	
	printf("Enter the Section Code:");
	
	section=SecCode(1);
	printf("Enter Student's ID:");
	student_id=StudentId(1);
	
	
	/*------------------------------------------*/

  do
	{
		
	do
		{
			mark=Mark();
			
			total_marks=total_marks+mark;
			
		    PrintIt(student_id, mark);
			
			printf("Enter Student's ID[0 to quit]:");
			student_id=StudentId(0);
			total_students_counter++;              /* student counter */
			
		}while(student_id!=0);
		
		studnt_section_aver = total_marks/total_students_counter;
//printf("\ntell me how many students are there: %d",total_students_counter);
		printf("The Average for the section is %.2f%%",studnt_section_aver);
		printf("\n");
		
//		total_students_counter=0;

		printf("Enter the Section Code:[0 to quit]");
		section=SecCode(0);	
		course_aver=course_aver+studnt_section_aver;
		section_counter++;
		}while((section!=0) && printf("Enter Student's ID[0 to quit]:") && StudentId(0));
	
	master_aver = course_aver/total_students_counter;
	printf("The Average for the course is %.2f%%",master_aver);
	printf("\n");
	
	/*------------------------------------------*/
}

int SecCode(int small_var)  /*part1*/
{
	int sec_code;
	
		
    do
    {
		scanf("%d", &sec_code);
	}while((sec_code < ("%d", small_var) || sec_code > 4) && printf("Invalid value entered. Must be %d to 4, please re-enter:", small_var)); 
	return sec_code;
}


long StudentId(int small_var)   /*part2*/
{
	long id;
	do
	{
		scanf("%ld", &id);
	}while((id < ("%d", small_var) || id > 999999999) && printf("Must be 1 to 999999999. Re-enter:"));
	
	printf("\n");
	return id;
}


double Mark(void)   /*part3*/
{
	double stdmark;
	int i;
	double total=0;
	double average;
	
	for(i=0;i<7;i++)
	{
		printf("Enter Mark#%d:",i+1);
		scanf("%lf", &stdmark);
		total=total+stdmark;
	}
	
	/*printf("tell me what's in i: %d\n", i); */
	average=total;
	return average;
}


void PrintIt(int student_id,double mark)
{
	printf("%09d's total mark is: %.1f",student_id,mark);
	printf("\n");
}


int get_int(void)

here what i got:

nter the Section Code:1
Enter Student's ID:232323

Enter Mark#1:10
Enter Mark#2:20
Enter Mark#3:5.5
Enter Mark#4:5
Enter Mark#5:10
Enter Mark#6:6
Enter Mark#7:7
000232323's total mark is: 63.5
Enter Student's ID[0 to quit]:54545454

Enter Mark#1:1
Enter Mark#2:2
Enter Mark#3:3
Enter Mark#4:4
Enter Mark#5:5
Enter Mark#6:6
Enter Mark#7:7
054545454's total mark is: 28.0
Enter Student's ID[0 to quit]:0

The Average for the section is 45.75%
Enter the Section Code:[0 to quit]2
Enter Student's ID[0 to quit]:3434343

Enter Mark#1:7
Enter Mark#2:6
Enter Mark#3:5
Enter Mark#4:4
Enter Mark#5:3
Enter Mark#6:2
Enter Mark#7:1
000000000's total mark is: 28.0
Enter Student's ID[0 to quit]:0

The Average for the section is 39.83%
Enter the Section Code:[0 to quit]0
The Average for the course is 28.53%

th program wouldnt loop properly because it has pre condition the it enters the loop, and once reloops starts from the middle of "continued" preconditioned loop. the Average for the section is incorrect as well as Average for the course
If anyone could take a look, would be greatly appreciated, sorry for such a long post


thanx!

Seeing you have made some efforts in coding it yourself, I will take the trouble to go through your long post.

Here are the problems:

1. Initialize all your marks and counters when you declare them:

double mark=0.;
	double std_aver=0.;
	int total_students_counter=0;
	int section_counter=0;
	double studnt_section_aver=0.;
                double course_aver=0.;
	double master_aver=0.;

Remember, make it a habit to initialize your variables, especially those that you will be using for computation.

2. Reinitialize these two variables in the following locations:

do
{
	double total_marks = 0.;	
	total_students_counter=0;

	do
	{
                     /// blah blah blah rest of codes...

This step will correct your section average computation.

3. Computation for course counter is wrong. Use the following instead:

master_aver = course_aver/section_counter;

Note that I replace the total_students_counter with section_counter, because your "course_aver" variable is actually a total of "section averages".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.