Ophiuchus
Banned
So I have to make a simple grade book for my final project in my intro to C class.
I have to be able to enter the number of students in the class, enter their Test, Quiz, and homework grades. Average them for each student individually and then give the class overall average. Everything is working fine for the most part, but the issue I'm having is that once I input the values for one things say test grades. I cant figure out how to get the menu to repeat so I can then enter there homework and again for the quiz grades.
I thought I'd be able to make a separate function for the menu and just call it at the end of the case statements but that doesn't seem to be working for me. Another idea I had was to put the whole menu into a do while loop but again that's proving to be difficult for me with the limited knowledge I have of C so far. I'd appreciate any help. Here is my code so far
I have to be able to enter the number of students in the class, enter their Test, Quiz, and homework grades. Average them for each student individually and then give the class overall average. Everything is working fine for the most part, but the issue I'm having is that once I input the values for one things say test grades. I cant figure out how to get the menu to repeat so I can then enter there homework and again for the quiz grades.
I thought I'd be able to make a separate function for the menu and just call it at the end of the case statements but that doesn't seem to be working for me. Another idea I had was to put the whole menu into a do while loop but again that's proving to be difficult for me with the limited knowledge I have of C so far. I'd appreciate any help. Here is my code so far
Code:
// Gradebook.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
int tg,qg,hwg,soa,l, number,num;/*grades,loop*/
int total,numofstds,stdnum,numoftes,numofquiz,numofhw;/*total sum of all grades,number of students,student number*/
float toltestval,tolquizval,tolhwval;/*total test value,total quiz value,total hwk value*/
float tesavg,hwavg,quizavg;/*test average,hwk average*/
double stdavg[50];/*sum of all grades*/
int n, ans;
float find_avg(float, float, float);/*function that will find average*/
float find_avg(float tesavg, float quizavg, float hwavg)/*sum of all grades*/
{
float tolavg;
tolavg = (.5 * tesavg + .3 * quizavg + .2 * hwavg);
return(tolavg);
}
float calAve(void)
{
int sum = 0;
float temp;
printf("Enter number of Grades: ");
scanf("%i",&num);/*user input*/
for(n = 1; n<= num; ++n)/*loop*/
{
printf("Enter Grades");/*grades*/
scanf("%i",&tg);/*user input*/
sum = sum + tg;/*adds total values*/
}
temp = sum / (float)num;/*calculates the average*/
return temp;
}
void main(void)
{
/*intro*/
printf("\n\n\n");/*space*/
printf("Welcome to Your Gradebook\n\n");/*welcome*/
printf("You will be asked to enter,the student Test,Quizs,Homework,Numbers and Grades as well as the number of students, so that the average can be\n"); /*description of the program*/
printf("calculated and the student can get a final grade.\n\n\n");/*continuation of the description of the program*/
/*Asking for input*/
printf("\nEnter number of students: ");/*number of student*/
scanf("%i",&numofstds);/*user input*/
printf("\n\n");/*space*/
n=0;
while(n < numofstds) /*loop*/
{
n = n + 1;
printf("Please Choose a Number from The Following Menu\n\n");/*directions*/
printf("1. To Enter Test Grades\n");
printf("2. To Enter Quiz Grades\n");
printf("3. To Enter Homework Grades\n");
printf("4. For Summary Of Averages\n");
printf("5. To Quit\n\n");
printf("\n\n");/*space*/
printf("Enter a Number: ");
scanf("%i",&number);/*user input*/
printf("\n");/*space*/
switch(number){
case 1:
printf("Your choice is ( 1 )\n\n");
printf("Enter Tests: ");
tesavg = calAve();
printf("Tests Ave\n");
printf("%.2f",tesavg);
break;
case 2:
printf("Your choice is ( 2 )\n\n");
printf("Enter Quizs: ");
quizavg = calAve();
printf("Quizs Ave\n");
printf("%.2f",quizavg);
break;
case 3:
printf("Your choice is ( 3 )\n\n");
printf("Enter Homeworks: ");
hwavg = calAve();
printf("Homeworks Ave\n");
printf("%.2f",hwavg);
break;
case 4:
printf("Your choice is ( 4 )\n\n");
stdavg[n] = find_avg(tesavg, quizavg, hwavg);
break;
case 5:
printf("Your choice is ( 5 )\n\n");
printf("Will you like to Quit? 1 = Yes, 0 = NO\n");
scanf("%i", &number);
if (number == 1){
break;}
break;
default:
printf("Please Choose a Number from the Menu...!\n\n");
break;
printf("\n\n")/*space*/;}
//printf("The Student Average is %.2f \n", stdavg[n]);/*Student average*/
//printf("Test ave Quiz ave Hwk ave Overall ave\n\n");/*to display the table*/
//printf("%.2f %.2f %.2f %.2f\n"tesavg, quizavg, hwavg, stdavg[n]);/*displays the value on the table*/
}
}