Hi stahta01 thanks again, My apologies on putting back the trailing semi colon was a typo. I changed some things around and with your help and everyone else we finally got the program running!!!!
Thank you all for such patience and this community is really great and helpful. I have one last thing I need to do before I finish and its about the print format. In the file I open I have 3 number per row for 2 rows.
So something like 21 34 21
23 43 12.
The program prints them out in a striaght line. I've been googling some keywords to try to see how to do this but I must be wording it wrong. Can you guys give me a tip on what to search for I feel bad asking for any more help on something that I'm sure we have covered and I have forgotten lol.
I have posted the code to see it works ! I should of done that to start with. Thanks again everyone!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// function declarations
float schoolgrade(float x, float y, float z); // this will do the calculations
float useroutput(float CG, float HG, float MG, float FG); //this will print the ouput to the user
float school ();
int getchoice ();
int main ()
{
int choice; // local declarations
choice = getchoice();
}
float school ()
{
float homework = 0;
float midterm = 0;
float finalexam = 0;
float finalgrade = 0;
int student = 0;
int studentID = 1;
printf("Enter total number of students \n");
scanf("%d" ,&student);
while(student > 0)
{
printf ("Enter 3 grades for student %d\n", studentID);
scanf ("%f %f %f",&finalexam, &midterm, &homework);
if (finalexam <= 100 && finalexam >= 0 && midterm <= 75 && midterm >= 0 && homework <= 120 && homework >= 0)
{
finalgrade = schoolgrade(finalexam, midterm, homework);
useroutput(finalexam, midterm, homework, finalgrade);
system ("pause");
student--;
studentID++;
}
else
{
printf("Incorrect value entered \n");
}
}
}
float schoolgrade(float x, float y, float z)
{
float CG = 0;
float HG = 0;
float MG = 0;
float FG = 0;
FG = (x/100) * .30;
MG = (y/75) * .20;
HG = (z/120) * .50;
CG = (FG + MG + HG) * 100;
return CG;
}
float useroutput(float a, float b, float c, float d)
{
printf ("Final exam was %.f out of 100 \n", a);
printf ("Medterm exam was %.f out of 75 \n", b);
printf ("Homework assignments were %.f out of 120 \n ",c);
puts ("---------------------------------------- \n");
printf ("Grade is %.f \n", d);
}
int getchoice(void)
{
int num;
int choice;
FILE* outputfile;
FILE* inputfile;
do
{
printf(" Menu\n");
printf("<1>Read data from a file\n");
printf("<2>Read data interactively\n");
printf(" Enter choice:\n");
scanf("%d",&choice);
switch(choice)
{
case 1: outputfile = fopen("G:\\output.txt", "r");
while(fscanf(outputfile, "%d", &num) == 1 )
{
printf("%3d\n", num);
}
fclose(outputfile);
return 0;
break;
case 2: school();
break;
default: printf("Press enter a valid selection\n");
}
} while(choice <=2);
}
PS sorry about the weird formatting, I have been using visual studio express so to get it in plain text I just pasted into a note pad first.