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
you missing
else
before 'c' , 'f' branches. currently, positive grades become 'f'selse if (percent >= .7) { grades = "c"; }
and again
else if (percent >= .0) { grades = "f"; }
- you overwriting calculated grades line
grades = console.readline();
i believe may have intended:
console.writeline(grades);
- your app exit after calculation. suggest
console.readline
@ or similar @ end allow user view results
Comments
Post a Comment