Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main(){
- //Variables
- string grade = "";
- double value = 0.0;
- bool valid = true;
- //Input
- cout << "Enter a grade: " << endl;
- cin >> grade;
- //Validation
- if (!(grade.substr(0, 1) == "A" || grade.substr(0, 1) == "B" || grade.substr(0, 1) == "C" || grade.substr(0, 1) == "D" || grade.substr(0, 1) == "F"))
- {
- valid = false;
- }
- else if (grade.length() > 2)
- {
- valid = false;
- }
- else if (grade.length() == 2)
- {
- if (grade.substr(1, 1) != "+" || grade.substr(1, 1) != "-")
- {
- valid = false;
- cout << "stuff" << endl;
- }
- }
- //Assigning value to grade
- if (valid == true){
- if (grade.substr(0, 1) == "A"){
- value = 4.0;
- }
- else if (grade.substr(0, 1) == "F"){
- value = 0.0;
- }
- else if (grade.substr(0, 1) == "B"){
- value = 3.0;
- }
- else if (grade.substr(0, 1) == "C"){
- value = 2.0;
- }
- else if (grade.substr(0, 1) == "D"){
- value = 1.0;
- }
- // + or -
- if (grade.substr(1, 1) == "+"){
- value += 0.3;
- }
- else if (grade.substr(1, 1) == "-"){
- value -= 0.3;
- }
- }
- //Output
- if (valid == false){
- cout << "Input is invalid." << endl;
- }
- else if (valid == true){
- cout << "Numeric value: " << value << endl;
- }
- //Other
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement