#Expected 'while'

27 messages · Page 1 of 1 (latest)

finite wigeon
#
#include <iostream>

using namespace std;

char grade;
int numerical_grade;
bool finished_gradeOperation(false); 
char grades_modifier;

int main()
{

do{                                //Will repeat everything as long as bool is true
        grades_modifier = ' ';

            cout << "Input your grade: ";
    cin >> numerical_grade;

  if (numerical_grade >= 91){
   grade = 'A';
  if (numerical_grade >= 98)
    grades_modifier = '+';
  else if (numerical_grade <=93){
    grades_modifier = '-';
  }
   if (numerical_grade >= 81){
   grade = 'B';
  if (numerical_grade >= 88)
    grades_modifier = '+';
  else if (numerical_grade <=83){
    grades_modifier = '-';
  }
   if (numerical_grade >= 71){
   grade = 'C';
  if (numerical_grade >= 78)
    grades_modifier = '+';
  else if (numerical_grade <=73){
    grades_modifier = '-';
  }
   if (numerical_grade >= 61){
   grade = 'D';
  if (numerical_grade >= 68)
    grades_modifier = '+';
  else if (numerical_grade <=63){
    grades_modifier = '-';
  }
  if (numerical_grade <= 60 && numerical_grade >= 0){
    grade = 'F';
  }

  cout << grade << grades_modifier << '\n'; //Prints the grade with the respective modifier
  }
else cout << "That's not a valid grade" << '\n'; //If input is not valid
finished_gradeOperation = true;

}

while (finished_gradeOperation = true); //Be able to input another grade after each sorting
    return 0;
}
  }
}```
Can I get some help? I'm not sure what's the issue, could be the brackets from the if's. It returns "expected 'while' at the end of the input"
crisp turtleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

finite wigeon
#

(I get the error on the end line btw)

austere geode
#

The do while cicle requires a


do{
}while(conditions);

#

You forgot the wile at the end of the cicle.

karmic lily
#

no, the while is there, but it's in the wrong place

#

you have more than one error in the code, it seems

austere geode
#

Oh yeah I missed it. I just assumed that was something else

karmic lily
#

You need to fix your if brackets

#

this part:

   grade = 'A';
  if (numerical_grade >= 98)
    grades_modifier = '+';
  else if (numerical_grade <=93){
    grades_modifier = '-';
  }

has two { and only one }, something is wrong there

#

it looks like you just added }}} to the end of the code because you got missing bracket errors, but that's not how it works

finite wigeon
#

Ah right

#

I forgot to count

#

Thank you ima try to fix it now :p

karmic lily
#

your if should look like this:

statements;
}```
#

an easy way to not forget your closed brackets is to write them first. So first you write

}```
and then you add stuff inside
finite wigeon
#

Mhm will do will do

#

Lemme try it rq

karmic lily
#

one more thing: your while says while (finished_gradeOperation = true);
= will set it to true, you want == to check if it is true

finite wigeon
#

Do all "if" conditions require a bracket to start it?

if (numerical_grade >= 81){
   grade = 'B';
  if (numerical_grade >= 88)
    grades_modifier = '+';
  else if (numerical_grade <=83)
    grades_modifier = '-';
  }```
Would something like this be correct or do I need to add the brackets for each "if"
#

where I only added a bracket to the first condition @karmic lily

karmic lily
#

if there is only one line then you don't need brackets

#

until you add another line and forget to add them 😄

crisp turtleBOT
#

@finite wigeon Has your question been resolved? If so, run !solved :)

finite wigeon
#

ok yh I'm still fixing the code but I prob got it solved

#

@karmic lily ty :3

#

!solved