nested if statement in C# -


i command prompt come , correct answer bad score, if try type in grade (800) nothing. appreciated. new apologize coder isn't pretty.

        //variables         string firstname, lastname, grades = "";         double points = 0, percent = 0;           //greeting         console.writeline("the purpose of program allow teacher calculate percentage , final grade students in class.");          //display , inputs         console.writeline("\n\nplease enter students first name.");         firstname = console.readline();          console.writeline("\n\nplease enter students last name.");         lastname = console.readline();          console.writeline("\n\nplease enter points student received.\n\n");         points = convert.todouble(console.readline());          //display after points entered         if (points < 0 || points > 1000 )          {             console.writeline("bad score!");         }         else          {             percent = points / 1000;             if (percent >= .9)             {                 grades = "a";             }             else if (percent >= .8)             {                 grades = "b";             }             if (percent >= .7)             {                 grades = "c";             }             else if (percent >= .6)             {                 grades = "d";             }             if (percent >= .0)             {                 grades = "f";             }             else             {                  console.writeline("wrong!!");             }         }                        grades = console.readline();          //outputs         console.writeline(firstname);          console.writeline(lastname);         console.writeline(points);         console.writeline(percent.tostring("p"));         console.writeline("so made an" + grades);          //closing statement         console.writeline("goodbye");         environment.exit(1);     } } 

}

you've got bunch of problems

  1. you missing else before 'c' , 'f' branches. currently, positive grades become 'f's

    else if (percent >= .7) {     grades = "c"; } 

and again

    else if (percent >= .0)     {         grades = "f";     } 
  1. you overwriting calculated grades line

 grades = console.readline(); 

i believe may have intended:

console.writeline(grades); 
  1. your app exit after calculation. suggest console.readline @ or similar @ end allow user view results

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -