Error I can't figure out!
Sep 20, 2009 at 3:42am UTC
We are doing a project for my programming class and the assignment is to have a program that calculates GPA by semester. I have the calculations just fine but I can't get the Semesters to work. I'm not very good at c++, so I would appreciate your help! Below are the errors the compiling gives me:
hw2.cpp: In function âint main()â:
hw2.cpp:31: error: could not convert âSemNameâ to âboolâ
hw2.cpp:87: error: could not convert âSemName.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](-0x00000000000000001)â to âboolâ
Thank you!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#include <iostream>
#include <string>
using namespace std;
int main ()
{
cout << endl << "Please enter all the grades you wish to use for your GPA." << endl;
cout << endl << "When you have finished, enter N to indicate that you have no more grades." << endl;
cout << endl << "The highest acceptable grade is 100%, if you got higher than this congratulations but please enter only 100 as grade." << endl;
cout << endl;
float Grade = 0;
int NumClass = 0;
const int Stop = -1;
float GPAVal = 0;
float TotGPAVal = 0;
float GPA = 0;
std :: string SemName;
while (SemName)
{
cout << "Please enter name of the semester of grades you want to enter." << endl;
cin >> SemName;
cout << SemName << endl;
while ( Grade >= 0 && Grade <= 100 )
{
cout << endl << "Please enter grade: " ;
cin >> Grade;
if ( Grade <=100 && Grade >= 90 )
{
GPAVal = 4.0;
cout << "Grade: " << Grade << "%; GPA Value: 4.0" << endl;
TotGPAVal = TotGPAVal + GPAVal;
}
else if ( Grade < 90 && Grade >= 80 )
{
GPAVal = 3.0;
cout << "Grade: " << Grade << "%; GPA Value: 3.0" << endl;
TotGPAVal = TotGPAVal + GPAVal;
}
else if ( Grade < 80 && Grade >= 70 )
{
GPAVal = 2.0;
cout << "Grade: " << Grade << "%; GPA Value: 2.0" << endl;
TotGPAVal = TotGPAVal + GPAVal;
}
else if ( Grade < 70 && Grade >= 60 )
{
GPAVal = 1.0;
cout << "Grade: " << Grade << "%; GPA Value: 1.0" << endl;
TotGPAVal = TotGPAVal + GPAVal;
}
else if ( Grade < 60 && Grade >= 0 )
{
GPAVal = 0.0;
cout << "Grade: " << Grade << "%; GPA Value: 0.0" << endl;
TotGPAVal = TotGPAVal + GPAVal;
}
else if ( Grade = Stop )
{
GPA = (TotGPAVal / NumClass);
cout << endl<< "Your overall GPA, after " << NumClass << " courses, is " << GPA << "." << endl << endl;
}
else if ( Grade > 100 || Grade < -1 )
{
cout << "Sorry this is an invalid input, please rerun the program and try again." << endl;
}
else
{
cout << "Sorry this is an invalid input, please rerun the program and try again." << endl;
}
NumClass = NumClass + 1;
}
if (SemName = -1)
{
cout << "Thank you for using this program!" << endl;
}
}
return (0);
}
Sep 20, 2009 at 4:32am UTC
while (SemName)
does not make sense because an std::string can't be converted to a bool
(i.e., can't be converted to true or false).
Sep 20, 2009 at 7:55am UTC
As firedraco said it doesn't make sense and your also trying to convert a string into an integer.
if (SemName = -1)
Topic archived. No new replies allowed.