-1
私はこのプログラムを設計しようとしていますが、これは常に間違った等級入力エラーを誰にも私はどこでエラーを見つけるのを助けることができますか? 誰かが私の間違いを見て、正しい方向に私を押し込むことはできますか?私は誰の時間とアドバイスに感謝:)GPA電卓をCコード
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char str[100], ch;
int i, grade[20];
int p;
float credit[20], gpa = 0.0, totCredit = 0.0;
printf("SIKKIM MANIPAL INSTITUTE OF TECHNOLOGY\nMajhitar, Rangpo - 737136\n\nGPA CALCULATOR \n\n");
printf("PROGRAM CREATED BY: SHAMSH SAMEED ASHAN\n");
printf("FOR ANY INFO PLEASE CONTACT +91-9083454677\n\n");
printf("------*------*------*-----*------*------*------*------*------*------*------*------*------*------\n\n");
printf("NOTE:\n\n");
printf("1. Enter Grades in CAPITALS \n");
printf("2. Enter Grade and credit for the subjects in the following format:\n");
printf(" Example: |Subject 'n' (Grade|Credit):S4 |(If you enter S4 Here S is the grade and 4 is the credit)\n");
printf("3. If you have got 'F' grade then enter F followed by credit for that subject. \n 'F' grade subjects will not be used in calculation.\n\n");
printf("Enter Grade & Credits for each subject:\n\n");
printf("------*------*------*-----*------*------*------*------*------*------*------*------*------*------\n\n");
printf("Enter number of subject:");
scanf("%d",&p);
/* get the letter grade and credits from the user */
for (i = 0; i < p; i++) {
printf("Subject %d(Grade|Credit):", i + 1);
ch = getchar();
grade[i] = ch;
scanf("%f", &credit[i]);
getchar();
}
/* print the input grades and credits */
printf("\nSubject | Grade | Credit\n");
for (i = 0; i < p; i++) {
printf(" %d | %c | %.1f\n", i + 1, grade[i], credit[i]);
}
/* calculate gpa value */
for (i = 0; i < p; i++) {
switch (grade[i]) {
case 'S':
gpa = gpa + 10 * credit[i];
totCredit = totCredit + credit[i];
break;
case 'A':
gpa = gpa + 9 * credit[i];
totCredit = totCredit + credit[i];
break;
case 'B':
gpa = gpa + 8 * credit[i];
totCredit = totCredit + credit[i];
break;
case 'C':
gpa = gpa + 7 * credit[i];
totCredit = totCredit + credit[i];
break;
case 'D':
gpa = gpa + 6 * credit[i];
totCredit = totCredit + credit[i];
break;
case 'E':
gpa = gpa + 5 * credit[i];
totCredit = totCredit + credit[i];
break;
case 'F':
gpa = gpa + 0 * credit[i];
totCredit = totCredit + credit[i];
printf("\nNOTE: F Grade SUBJECTS will not be used in calculation.\n");
break;
default:
printf("WRONG GRADES FORMAT ENTERED\n PLEASE ENTER GRADES IN CAPITAL LETTERS!!\n\n");
exit(0);
}
}
printf("Total GPA: %.1f\tTotal Credit: %.1f\n", gpa, totCredit);
gpa = gpa/totCredit;
printf("Your GPA: %.2f\n", gpa);
printf("\nPress ENTER a few times to terminate the program");
fflush(stdout);
getchar(); getchar();
return 0;
}
どのようにデバッグを試みましたか?たとえば、数値が配列に正しく読み込まれていることを確認しましたか?いくつかの簡単なprintfは非常に長い道を行くことができます。 –
いいえ私はそれをデバッグしていません。 –
@ShamshSameedAhsanしかし、スタックオーバーフローを尋ねるのがデバッグよりもこの問題を解決する良い方法だと思います。 – jotik