-6
#include <iostream>
#include <string>
#include <sstream>
#include <unistd.h>
using namespace std;

int main()
{   
    int score;
    string name, sco;
    cout<<"Hello! I am Mrs. Marian! I am the administratress of this humble website!"<<'\n';
    cout<<"This website is kindly brought to you by our Prime Minister Candry Veneroth."<<'\n';
    cout<<"This is the 'National School Grading System', or the NSGS, to help you see if your student fails or not."<<'\n';
    cout<<"The first thing you have to do is type the student's name: "<<'\n';
    getline(cin,name);
    cout<<"Great! Now please enter "<<name<<"'s correct answers in the National Education Test: ";
    getline(cin,sco);
    stringstream(sco)>>score;
    cout<<"The NET (National Education Test) has a total score of 180 with 150 questions with each question having a score of 1.2"<<'\n';
    cout<<"Loading data"<<'\n';

    if (score*1.2<90, score*1.2>=0)
    {
        cout<<"The student "<<name<<" has NOT PASSED, with a score of "<<score*1.2<<". I am sorry, and hope the best for next time.";
    }
    else if (score*1.2<180, score*1.2>=90)
    {
        cout<<"CONGRATULATIONS!"<<'\n'<<"The student "<<name<<" has PASSED, with a score of "<<score*1.2<<". Once again, congratulations!";
    }
    else if (score*1.2==180)
    {
        cout<<"CONGRATULATIONS!!!"<<'\n'<<"The student "<<name<<" has PASSED with a perfect score of "<<score*1.2<<". You will have a bright future ahead of you, "<<name<<". And I hope you for a bright future";
    }
    else if (score*1.2>180, score*1.2<0)
    {
        cout<<"This is invalid, and entering an invalid score in the NSGS is considered an act of malice against the students of Lantreind and is illegal according to the National Education Test Act (NETA) verse 5:";
        cout<<'\n'<<"'For thee who dare to destroy a student's scores, shall be convicted in the name of the Veneroth name.'"<<'\n'<<"You have been warned.";
    }
}

Okay, Ii! I am a newbie! Practicing the 'if else' function.. I want to be able to do it like this:

  1. If the score is 0-89, they don't pass.
  2. If the score is 90-179, they pass.
  3. If the score is 180, they pass with a perfect score! Yay!
  4. If the score is under 0, or above 180, I wanted the program to tell them to do it right.

I've been tinkering with the code, and at first, the first and second 'if and if else(s) 'does not have the 'code after the commas'. So, even though the score is 180 or -897 or 1131, it will still say they (PASS/NOT PASS), completely ignoring the 3rd and 4th 'if else(s)'.

Oh! And also, I would like to "pause(1)" as evident to why i put # include , but it doesn't work! The message was =

error : too many arguments to function 'int pause ()'

I really don't know how to fix this, and I hope that anyone could help me figure out what is wrong and how to fix it and make it do the way it is supposed to..

Thank you!

Sincerely, Crunch Gum

  • 5
    `score*1.2<90, score*1.2>=0` is equivalent to `score*1.2>=0` because the left operand of comma operator will be thrown away. Also be careful about errors in floating point aritimetic. – MikeCAT Dec 15 '15 at 14:11
  • 5
    Pick up one or more books from the [The Definitive C++ Book Guide and List](http://stackoverflow.com/q/388242/1889329), and read them. – IInspectable Dec 15 '15 at 14:14
  • Try using `score*1.2 > 0 && score*1.2 < 90` – enrm Dec 15 '15 at 14:19
  • editing your if statements from " , " to " && " will do the job as @enrm mentioned above – QuestionsEverywhere Dec 15 '15 at 14:20
  • In the last if statement you have to change "," to "||" since in this condition you only need one of the conditions. – Egl Dec 15 '15 at 14:26
  • "Thee" makes no sense at all (it's the objective case of "thou") and you can't use both "thou" and "you" to address the same person. – molbdnilo Dec 15 '15 at 14:27
  • `if` and `else` are keywords. They are not functions. – Pete Becker Dec 15 '15 at 15:07

2 Answers2

3
  • Use && operator if you want to make the result true only if both of the condition is true.
  • You won't need the last condition because all of "score"s which aren't caught by previous conditions.
  • You should use variables to avoid doing the same calculation many times.
  • Be careful about errors in floating point aritimetic. I think you should avoid using floating point values if you can.

possible fix:

#include <iostream>
#include <string>
#include <sstream>
#include <unistd.h>
using namespace std;

int main()
{

    int score;
    string name, sco;
    cout<<"Hello! I am Mrs. Marian! I am the administratress of this humble website!"<<'\n';
    cout<<"This website is kindly brought to you by our Prime Minister Candry Veneroth."<<'\n';
    cout<<"This is the 'National School Grading System', or the NSGS, to help you see if your student fails or not."<<'\n';
    cout<<"The first thing you have to do is type the student's name: "<<'\n';
    getline(cin,name);
    cout<<"Great! Now please enter "<<name<<"'s correct answers in the National Education Test: ";
    getline(cin,sco);
    stringstream(sco)>>score;
    cout<<"The NET (National Education Test) has a total score of 180 with 150 questions with each question having a score of 1.2"<<'\n';
    cout<<"Loading data"<<'\n';

    int mscore = score * 12;

    if (mscore<900 && mscore>=0)
        {
            cout<<"The student "<<name<<" has NOT PASSED, with a score of "<<score*1.2<<". I am sorry, and hope the best for next time.";
        }
    else if (mscore<1800 && mscore>=900)
        {
            cout<<"CONGRATULATIONS!"<<'\n'<<"The student "<<name<<" has PASSED, with a score of "<<score*1.2<<". Once again, congratulations!";
        }
    else if (mscore==1800)
        {
            cout<<"CONGRATULATIONS!!!"<<'\n'<<"The student "<<name<<" has PASSED with a perfect score of "<<score*1.2<<". You will have a bright future ahead of you, "<<name<<". And I hope you for a bright future";
        }
    else
        {
            cout<<"This is invalid, and entering an invalid score in the NSGS is considered an act of malice against the students of Lantreind and is illegal according to the National Education Test Act (NETA) verse 5:";
            cout<<'\n'<<"'For thee who dare to destroy a student's scores, shall be convicted in the name of the Veneroth name.'"<<'\n'<<"You have been warned.";
        }
}
MikeCAT
  • 73,922
  • 11
  • 45
  • 70
0

Change: if (score*1.2<90, score*1.2>=0)
Use: if (score*1.2<90 && score*1.2>=0)
Since you want to accomplish both conditions

Change: else if (score*1.2<180, score*1.2>=90)
Use: else if (score*1.2<180 && score*1.2>=90)
Since you want to accomplish both conditions

Change: else if (score*1.2>180, score*1.2<0)
Use: else if (score*1.2>180 || score*1.2<0)
Since you want to accomplish one of these two conditions

Egl
  • 774
  • 7
  • 20