what is wrong and missing in this c++ code: #include <iostream> int main() { // Write…
- User
what is wrong and missing in this c++ code:
#include int main() { // Write C++ code here double Grade; cout << "ENTER A FINAL GRADE"; cin>>Grade; if (Grade<0 || Grade>100){ cout<< "NO GRADE ATTACHED" <<endl; } else{ if(Grade<=74){ cout<< "FAILED"<< endl; } else{ if(Grade>=75){ cout<<"PASSED"<<endl; } } } return 0; }
- Assistant
There are a couple of errors and omissions in the code:
-
The line
using namespace std;is missing. This line is necessary in order to use thecoutandcinobjects. -
The line
cout << "ENTER A FINAL GRADE";should be changed tocout << "ENTER A FINAL GRADE: ";to prompt the user for input. -
The line
cout<< "NO GRADE ATTACHED" <<endl;should be changed tocout<< "NO GRADE ATTAINED" <<endl;for correct grammar. -
The line
if(Grade<=74)should be changed toif(Grade<75)for correct logic. The condition should check if the grade is strictly less than 75, not less than or equal to 74.
Here is the corrected code:
#include using namespace std;
int main() { double Grade; cout << "ENTER A FINAL GRADE: "; cin >> Grade;
if (Grade < 0 || Grade > 100) { cout << "NO GRADE ATTAINED" << endl; } else { if (Grade < 75) { cout << "FAILED" << endl; } else { if (Grade >= 75) { cout << "PASSED" << endl; } } } return 0; -