So, I'm relatively new to programming and I'm working on a program that allows for input of grades, course hours, and then calculates GPA based on that. But, I'm going step by step, the first thing I'm trying to do is ensure that I can input the data so that it is properly assigned to memory in the two arrays I've created. However, I'm getting some weird output when I run the program. Each array needs to store 5 values, so... 5 grades and then the course hours for those five courses.
#include <stdio.h>
int main()
{
char grades[5]; // create array to store letter grades
int hours[5]; // create array to store hours
int x; // counter
for (x = 0; x < 4; ++x) // stores letter grades in array
{
puts("Please enter letter grade: ");
scanf("%c\n", &grades[x]);
}
int y;
for (y = 0; y < 4; ++y)
{
puts("Please enter course hours: ");
scanf("%d\n", &hours[y]);
}
return 0;
}
So, it seems my first loop works fine for inputting letter grades. There is a weird thing though. After entering the letter grade for the first course it prompts the user again to enter a letter grade (which is fine), it does this for the entry of all five values EXCEPT the second one. There's just a blank line where you can enter the value and then the program carries on. I've been able to print the values of the array and it seems to be taking the data fine, it's just a weird little thing I noticed.
The real problem is the data input for the second array for course hours. It prints the prompt 4 times, and doesn't allow any input of data.