Ich schreibe einen GPA-Rechner. Ich habe Probleme mit der OR (||) -Funktion, um zu überprüfen, ob die Eingabe für Guthaben korrekt oder nein ist (wenn sie falsch ist, sollte sie erneut fragen). Wenn die Eingabe für Noten "I" oder "W" ist, sollte das Programm diese Information nicht verwenden (es sollte nichts dagegen tun). Vielen Dank für die Hilfe. Hier ist der Code:GPA-Rechner. Probleme mit ODER und Division durch 0
// Include Statements
#include <iostream>
using namespace std;
//Program to calculate GPA
int main()
{
// Program made by Jose Luis Landivar
// Fall 2016
cout << ""<< endl;
cout << "The following program will calculate your GPA "<< endl<<'\n';
char grade;
int g = 1;
//variables for the algebraic operations needed
int credit = 0;
int totalcredit = 0;
int ptotal = 0;
double gpa, p = 1;
double count = 1;
double nclass;
string coursename, coursenumber;
cout << "Please enter the number of classes for the GPA calculator"<< endl;
cin >> nclass;
cout << ""<< endl;
while (count <= nclass) // While
{
//Information for the class
cout << "Please enter the course name for the class # "<< count << endl;
cin >> coursename;
cout << "Please enter the course number for the class # "<< count << endl;
cin >> coursenumber;
//Getting grades and credits from user
cout << "Enter the grade for the class # "<< count <<" (A,B,C,D,F,I,W)"<< endl;
cin >> grade;
if (grade == 'A' || grade == 'B' || grade == 'C' || grade == 'D' || grade == 'F' || grade == 'I' || grade == 'W')
{
// If for grades
if (grade == 'A')
{
g = 4;
cout << "Enter the number of credits for the class # "<< count <<" (1,2,3,4,5)"<< endl;
cin >> credit;
cout << ""<< endl;
if (credit == 5 || credit == 4 || credit == 3 || credit == 2 || credit == 1){
p = g * credit;
totalcredit = totalcredit + credit;
ptotal = ptotal + p;
}
else {cout << "Input is incorrect\n";
}
}
if (grade == 'B')
{
g = 3;
cout << "Enter the number of credits for the class # "<< count <<" (1,2,3,4,5)"<< endl;
cin >> credit;
cout << ""<< endl;
if (credit == 5 || credit == 4 || credit == 3 || credit == 2 || credit == 1){
p = g * credit;
totalcredit = totalcredit + credit;
ptotal = ptotal + p;
}
else {cout << "Input is incorrect\n";
}
}
if (grade == 'C')
{
g = 2;
cout << "Enter the number of credits for the class # "<< count <<" (1,2,3,4,5)"<< endl;
cin >> credit;
cout << ""<< endl;
if (credit == 5 || credit == 4 || credit == 3 || credit == 2 || credit == 1){
p = g * credit;
totalcredit = totalcredit + credit;
ptotal = ptotal + p;
}
else {cout << "Input is incorrect\n";
}
}
if (grade == 'D')
{
g = 1;
cout << "Enter the number of credits for the class # "<< count <<" (1,2,3,4,5)"<< endl;
cin >> credit;
cout << ""<< endl;
if (credit == 5 || credit == 4 || credit == 3 || credit == 2 || credit == 1){
p = g * credit;
totalcredit = totalcredit + credit;
ptotal = ptotal + p;
}
else {cout << "Input is incorrect\n";
}
}
if (grade == 'F')
{
g = 0;
cout << "Enter the number of credits for the class # "<< count <<" (1,2,3,4,5)"<< endl;
cin >> credit;
cout << ""<< endl;
if (credit == 5 || credit == 4 || credit == 3 || credit == 2 || credit == 1){
p = g * credit;
totalcredit = totalcredit + credit;
ptotal = ptotal + p;
}
else {cout << "Input is incorrect\n";
}
}
count = count + 1;
}
else {cout << "Input is incorrect\n";
}
}
//algebraic formulas
gpa = ptotal/totalcredit;
//output results
cout << "Your total number of credits is: " << totalcredit << endl;
cout << "Your GPA is: " << gpa << endl;
if (grade == 'I')
{
}
if (grade == 'W')
{
}
return 0;
}
"Ich habe Probleme mit der OR (||) -Funktion" können Sie angeben, welche Probleme Sie damit haben? –