# Gpa calculator any ideas

This is a discussion on Gpa calculator any ideas within the C Programming forums, part of the General Programming Boards category; i want my variable (j) to be various and make sure the loop runs from the point of view of ...

1. ## Gpa calculator any ideas

i want my variable (j) to be various and make sure the loop runs from the point of view of (j) which can be any number causing it to repeat any help ??!!
and how would i go about making the module grade and id print the result with my function and a grade point value
and also make it do calculation like Grade point value and total module credits 5 per subject...Which there are twelve

Code:
#include <stdio.h>
Code:
#include <stdlib.h>

struct input{
char fname[12];
char lname[12];
char studentid[10];
char moduleid[10];
};
void Grade(struct input data);
void GPV(struct input data);

int main()
{
int i,j;
struct input words[120];
struct input data[15];

printf("*-----------Welcome To The GPA CALCULATOR----------*");

printf("\n \nHow Many students would you like to enter: ");
scanf("%d",&j);

for(j=0;j<100;j++)

{

printf("\n\nEnter The First Name & Last Name & Student ID:\n");
scanf("%s %s %s",words[j].fname,words[j].lname,words[j].studentid);

for(i=0;i<12;i++)
{
printf("\n\nEnter The Module ID & Module Grade Achieved:\n");
}
}

return 0;
}
void Grade(struct input data )
{

{
printf("A");
}
{
printf("B+");
}
{
printf("B");
}
{
printf("B-");
}
{
printf("C+");
}
{
printf("C");
}
{
printf("D");
}
if (data.modulegrade <35 )
{
printf("F");
}
return ;
}

2. You can't use the same variable for "the number of total students" and "the # for the current student I'm working with". j is okay for the latter; you should probably use a more meaningful name (like num_students or similar) for the first.

Currently you can only store one modulegrade for each student, so asking for 12 of them just means that 11 of them are going to be thrown away. Perhaps you want an array of those instead? (Same for module ID.)

3. But I declared module I'd as character array,I could change j to a variable from before I called studamnt; , but how would I cause the stud amount to change depending on how many students intake and make it loop ?

4. Originally Posted by Junior Aj Twist
But I declared module I'd as character array,I could change j to a variable from before I called studamnt; , but how would I cause the stud amount to change depending on how many students intake and make it loop ?
If I have successfully translated this question to English, the answer is that j is just fine as it is. This line right here, however:
Code:
scanf("%d",&j);
needs to send that typed-in number into some other variable other than j. You want j to go from 0 to <some number that gets typed in>, so you had better store <some number that gets typed in> in a variable that has a name that isn't j.

5. So if I added

int studamnt;

Printf("\n \nHow many students would you like to enter: ");
Scanf("%d",&studamnt);

How would this enable my loop to fire depending on my studamnt in respect
To j

Would I make studamnt a array?
And make it &studamnt[j]
In the scanf

6. Originally Posted by Junior Aj Twist
So if I added

int studamnt;

Printf("\n \nHow many students would you like to enter: ");
Scanf("%d",&studamnt);

How would this enable my loop to fire depending on my studamnt in respect
To j
That would work fine, because you can use j<studamnt as your stop condition in your for loop.

Originally Posted by Junior Aj Twist
Would I make studamnt a array?
And make it &studamnt[j]
In the scanf
Why would you want it to be an array? The number of students is just that, a number; it's not a series of numbers.

(If you mean that you want to input the number of classes instead of having i always go to 12, then that means you would need to store that number in your struct with the other information about your student.)

7. Thanks a lot for helping me solve the varying problem mate , how would I go about
The void GPV function
How do I involve numbers of the grade point value in the module grade
I'm working with floats of 4.00 downwards

Would it make sense regarding my if statements to use a printf again for the GPV ?

Popular pages Recent additions