Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

so im trying to check to see if the input is greater than 100 or a letter( if(gr

ID: 3885636 • Letter: S

Question

so im trying to check to see if the input is greater than 100 or a letter( if(grade > 100 || !isdigit(grade))). I thought this code would work but it doesnt work correctly. it only works if I take out the || !isdigit(grade) part, but i dont understand why. I tried isalpha 100 but same result. please help!!!

#include "student.cpp"

#include <iostream>
using namespace std;

class Student
{
public:
   string name();
   void exam(double grade);
   double average();
   Student(string name);
  
private:
   string student_name;
   double exam_sum;
   double exam_num_grades;

};

Student::Student(string name)
{
student_name = name;
exam_sum = 0;
exam_num_grades = 0;
}

string Student::name()
{
return student_name;
}

void Student::exam(double grade)
{
    exam_sum += grade;
exam_num_grades++;
}

double Student::average()
{
   if(exam_num_grades == 0)
   {
       return 100;
   }
   else
   {
       return exam_sum / exam_num_grades;
   }
}

My Main Code:

#include <iostream>
#include <string>
#include <ctype.h>
#include "student.cpp"

using namespace std;

double studentGrade(double grade);

int main(void)
{
   double grade;
   string name;

   cout << "Please Enter Student's Name: ";
   getline(cin, name);

   Student student = name;

   for(int i = 0; i >= 0; i++)
   {  
       cout << "Enter Student Grade: ";
       cin >> grade;

       if(grade < 0)
       {
           break;
       }
       else if(grade > 100)// || !isdigit(grade))
       {
           cout << "ERROR: INVALID INPUT. TRY AGAIN! ";
           cout << "Enter Student Grade: ";
           cin >> grade;
       }
       else
       {
           student.exam(grade);
       }
   }
   cout << student.name() << "'s average is: " << student.average() <<' ';
}

Explanation / Answer

Edit the word ex_am and then run the code
main.java
--------------------------
#include<iostream>
using namespace std;
#include "student.cpp"
int main(){
    string name;
    short int ctr=0;
    double grade;
    cout<<"Enter your name: ";
    getline(cin, name);
    Student student{name};
    do{
        cout<<"Enter "<<ctr+1<<" grade: ";
        cin>>grade;
        ctr++;
        if(grade>0){
            student.ex_am(grade);
        }
    }while(grade>0);
    cout<<student.name()<<" has an average of "<<student.average()<<" ";
}
-----------------------------------
Student.cpp
-----------------
class Student{
private:
    string student_name;
    double exam_sum, exam_num_grades;
public:
    Student(string name): student_name{name}, exam_sum{0}, exam_num_grades{0} { }
    string name(){
        //cout<<student_name;
        return student_name;
    }
    void ex_am (double grade){
        exam_sum += grade;
        //grade += exam_sum;
        exam_num_grades ++;

    }
    double average(){
        double avg;
        if (exam_num_grades==0)
        { avg = 100; }
        else
            avg = (exam_sum)/(exam_num_grades);
        // cout<<avg<<endl;
        return avg;
    }

};