Problems integrating while()loop into the if/else statement.

Hey guys. Having trouble with some concepts. I think I've mostly got the while()loop concept figured out. But have a question. If I integrate the if/else statement into the loop, does it still terminate when the loop shuts off when hitting that sign? For example, if while(name!<90), then if I enter 90 the loop shuts off right? And if so, do the if/else statements shut off as well? Thank you. Here is a copy of what I am refering to.

Topics



Loops

while Statement



Description

Write a program that computes the letter grades for the students in a class given their test scores. A student test score varies from 0 to 100. For each student, the program first asks the student’s name and then the student’s test score. It then displays the student name, test score and the letter grade. It repeats this process for each student.

The program calculates the letter grade from the test score as below:

A is 90 to 100 points

B is 80 to 89 points

C is 70 to 79 points

D is 60 to 69 points

F is 0 to 59 points.



/*

Java

*/

The user indicates the end of data by pressing the cancel button in the input dialog box when asked for a student name.



/*

C++

*/

The user indicates the end of data by entering two consecutive forward slashes ( // ) when asked for the name.





At the end, the program displays a summary report including the following:



· The total number of students.

· The total number of students receiving grade “A”.

· The total number of students receiving grade “B”.

· The total number of students receiving grade “C”.

· The total number of students receiving grade “D”.

· The total number of students receiving grade “F”.



Testing



Test Run 1

(User input is shown in bold).



Enter Student Name

Alan

Enter Student Score

75



Alan 75 C



Enter Student Name

Bob

Enter Student Score:

90



Bob 90 A





Enter Student Name

Cathy

Enter Student Score

80



Cathy 80 B



Enter Student Name

Dave

Enter Student Score:

55



Dave 55 F





Enter Student Name

Eve

Enter Student Score

85



Eve 85 B



Enter Student Name

(Java users, push the Cancel Button)

(C++ users, enter two consecutive forward slashes for the name).



Summary Report

Total Students count 5

A student count 1

B student count: 2

C student count 1

D student 0

F students 1




For example, if while(name!<90), then if I enter 90 the loop shuts off right?


I think you meant (name<90). But anyway, the loop ends when the while condition is actually tested and found to be false. If there is a lot of code within the loop, all that code will continue to be executed until the closing brace } is encountered, then the condition is checked, and if it is false the loop will terminate.
Topic archived. No new replies allowed.