This is what I have right now, I need it to calculate and print the gpa but I have no clue on how to do it.
The text document I am using has the following in it:
Intro to Programming in C:4.5:3.67
Intermediate Accounting:5:4.00
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <iostream>
void getchoice (void);
void getinfo (void);
int main (void)
{
int choice;
getchoice ();
return 0;
}
void getchoice (void)
{
int choice;
do
{
printf ("Select where to print transcript: 1 to file or 2 to screen");
scanf ("%d", &choice);
if (choice == 1)
{
printf ("printing to file\n");
}
else if (choice == 2)
{
printf ("printing to screen\n");
getinfo ();
}
else
{
printf ("please choose either 1 or 2");
}
}
while (choice != 1 && choice != 2);
}
void getinfo (void)
{
FILE * in;
FILE * out;
float units;
float gpa;
char var;
if ( (in = fopen ("record1.txt", "r")) == NULL)
{
printf ("error opening file");
}
while ((fscanf_s(in, "%c", &var)) != EOF)
{
printf ("%c", var);
if (var == ':')
{
fscanf (in, "%f:%f", &units, &gpa);
}
}
fclose (in);
}
This is the conversion table I came up with
Code:
if (gpa >= 3.99 && gpa <= 4.01)
printf ("A");
else if (gpa >= 3.66 && gpa <= 3.68)
printf ("A-");
else if (gpa >= 3.32 && gpa <= 3.34)
printf ("B+");
else if (gpa >= 2.99 && gpa <= 3.01)
printf ("B");
else if (gpa >= 2.66 && gpa <= 2.68)
printf ("B-");
else if (gpa >= 2.32 && gpa <= 3.34)
printf ("C+");
else if (gpa >= 1.99 && gpa <= 2.01)
printf ("C");
else if (gpa >= 1.66 && gpa <= 1.68)
printf ("D+");
else if (gpa >= 1.32 && gpa <= 1.34)
printf ("D");
else if (gpa >= 0.99 && gpa <= 1.01)
printf ("D-");
else
printf ("F");