Hey there,
i have this following code i'd like some feedback from if possible(comments, critism, tips)
I'm a newb with C++ and currently trying to grasp the concepts of OOP
two files, main.cpp and a header file:
source file:
header file:Code:/* * File: main.cpp * Author: joe * * Created on September 15, 2008, 4:44 PM */ #include "scoreLib.h" int main() { float input; std::cout << "Please enter a score: "; if(std::cin >> input) { Score student(input); student.gradeResult(); std::cout << "Your Score is: " << input << std::endl; } else { std::cout << "Please enter a numeric value" << std::endl; } return 0; }
I'm currently trying to fix this bug where by if you entered say for instance 3e3, it will still exectute:Code:/* * File: scoreLib.h * Author: joe * * Created on September 15, 2008, 4:44 PM */ #include <iostream> #ifndef _SCORELIB_H #define _SCORELIB_H class Score { float *numGrade; public: Score(float); ~Score(); void gradeResult(){ if((*numGrade >= 95) && (*numGrade <= 100)) { std::cout << "Merit!\n"; } else if((*numGrade >= 80) && (*numGrade <= 94)) { std::cout << "Pass!\n"; } else if((*numGrade >= 65) && (*numGrade <=79)) { std::cout << "Partial Resit\n"; } else if((*numGrade >= 50) && (*numGrade <= 64)) { std::cout << "Full Resit\n"; } else if((*numGrade >= 0) && (*numGrade <= 49)) { std::cout << "Fail!\n"; } else { std::cout << "Sorry enter a number between 1 and 100\n"; } } }; Score::Score(float defaultScore) { numGrade = new float; *numGrade = defaultScore; } Score::~Score() { delete numGrade; } #endif /* _SCORELIB_H */
which it shouldnt, but am having some difficulty trying to figure out why it does this, help MUCH appreciated, thanks in advanceCode:std::cout << "Your Score is: " << input << std::endl;

