K
Kelth.Raptor
Im having some difficulty with strings here, I hope someone is kind
enough to help, I do appreciate it. Im working on a grade point
average calculator for my intro to programming class and I thought I
would go a bit above and beyond the scope of the class and use
strings. But I ran into a snag with my getgrades function. The
compiler gives me the error: "81 ISO C++ forbids comparison between
pointer and integer"
here is the code for the function
float getgrades(int num) // gets the grade for the class
{
int i;
float grade;
char str[10];
for(i=0;i=9;i++) str=0; //reset's the string
cout << "\n Please enter the grade for your number " << num << "
class. (from A to F) \n";
gets(str);
if((bool) str[1] == false) // is neither + or -, null terminator
located at str[1]
{
if(str[0] == "A") grade = 4.0;
else if(str[0] == "B") grade = 3.0;
else if(str[0] == "C") grade = 2.0;
else if(str[0] == "D") grade = 1.0;
else if(str[0] == "F") grade = 0;
}
else if(str[1] == "+") // entered +
{
if(str[0] == "B") grade = 3.4;
else if(str[0] == "C") grade = 2.4;
else if(str[0] == "D") grade = 1.4;
}
else if(str[1] == "-") // entered -
{
if(str[0] == "A") grade = 3.7;
else if(str[0] == "B") grade = 2.7;
else if(str[0] == "C") grade = 1.7;
else if(str[0] == "D") grade = 0.7;
}
/* failed switch statement-------->
switch(str[1]) {
case "A":
grade = 4.0;
/*case "A-":
grade = 3.7;
case "B+":
grade = 3.4;
case "B":
grade = 3.0;
case "B-":
grade = 2.7;
case "C+":
grade = 2.4;
case "C":
grade = 2.0;
case "C-":
grade = 1.7;
case "D+":
grade = 1.4;
case "D":
grade = 1.0;
case "D-":
grade = 0.7;
case "F":
grade = 0;
default:
cout << "Pease enter a valid grade A-F";
}
*/
return grade;
}
Any ideas? I would greatly appreciate it, thanks again
-Nick
enough to help, I do appreciate it. Im working on a grade point
average calculator for my intro to programming class and I thought I
would go a bit above and beyond the scope of the class and use
strings. But I ran into a snag with my getgrades function. The
compiler gives me the error: "81 ISO C++ forbids comparison between
pointer and integer"
here is the code for the function
float getgrades(int num) // gets the grade for the class
{
int i;
float grade;
char str[10];
for(i=0;i=9;i++) str=0; //reset's the string
cout << "\n Please enter the grade for your number " << num << "
class. (from A to F) \n";
gets(str);
if((bool) str[1] == false) // is neither + or -, null terminator
located at str[1]
{
if(str[0] == "A") grade = 4.0;
else if(str[0] == "B") grade = 3.0;
else if(str[0] == "C") grade = 2.0;
else if(str[0] == "D") grade = 1.0;
else if(str[0] == "F") grade = 0;
}
else if(str[1] == "+") // entered +
{
if(str[0] == "B") grade = 3.4;
else if(str[0] == "C") grade = 2.4;
else if(str[0] == "D") grade = 1.4;
}
else if(str[1] == "-") // entered -
{
if(str[0] == "A") grade = 3.7;
else if(str[0] == "B") grade = 2.7;
else if(str[0] == "C") grade = 1.7;
else if(str[0] == "D") grade = 0.7;
}
/* failed switch statement-------->
switch(str[1]) {
case "A":
grade = 4.0;
/*case "A-":
grade = 3.7;
case "B+":
grade = 3.4;
case "B":
grade = 3.0;
case "B-":
grade = 2.7;
case "C+":
grade = 2.4;
case "C":
grade = 2.0;
case "C-":
grade = 1.7;
case "D+":
grade = 1.4;
case "D":
grade = 1.0;
case "D-":
grade = 0.7;
case "F":
grade = 0;
default:
cout << "Pease enter a valid grade A-F";
}
*/
return grade;
}
Any ideas? I would greatly appreciate it, thanks again
-Nick