私は、新しい(を使用して)コースの数を入力するように促す簡単なGPA電卓を作成しようとしています。これに続いて、コースの数に依存するforループがあり、ユーザーにクラスのグレードとクレジットの数を入力するように要求されます。プログラムはループとエラーを完了します。助けてください。ここでは、コード(私の初めてところで、このフォーラムのサイトを使用して)です:基本的なC++ベースのGPA計算機とシムの使用の支援
#include <iostream>
#include <conio.h>
using namespace std;
int main(){
cout<<"Welcome to the GPA calculator";
cout <<endl;
cout<<"Please enter the number of courses you wish to calculate : ";
int*numberOfCourses = new int;
cin>>*numberOfCourses; //must dereference as it is a pointer and I AM SETTING variable.
char grade, *credits= new char;
int gradesOfPerson = 0;
int*score = new int;
int j = 0;
int i = 0;
int*cumulativeScore= new int;
while(i< *numberOfCourses){
cout <<"Please enter the credits of your " <<(i+1) <<" course. " ;
cin >>*credits;
cin.get();
cout << "Please enter your grade :";
cin>>(grade);
cout <<endl;
switch (grade){
case 1: if (grade=='A'){
*score = 4;
break; }
case 2: if (grade=='B'){
*score = 3;
break; }
case 3: if (grade=='C'){
*score = 2;
break; }
case 4: if (grade=='D'){
*score = 1;
break; }
case 5: if (grade=='D'){
*score = 1;
break; }
case 6: if (grade =='E'){
*score = 0;
break;
}
}
gradesOfPerson = ((*score)*(*credits));
cumulativeScore += gradesOfPerson;
i++;
}
int gpa = (*cumulativeScore)/(*numberOfCourses);
cout <<"Your GPA is : " <<gpa;
delete numberOfCourses, credits, score, cumulativeScore;
}
それは間違って何を言うのは難しいエラーを見ずに
このプロジェクトでは動的割り当て( 'new')は必要ありません。すべてのスコアを一度に格納する必要がある場合は、動的配列が必要です(ただし、 'std :: vector'が詳細を処理するのに最適です)。しかし、GPAを計算するには、総クレジット。 'new'と' delete'をスキップします。 –