Download Lab 8 - CPS 196 Fall 2007: Observing if Statements & Writing Alternating Harmonic Series and more Lab Reports Computer Science in PDF only on Docsity! CPS 196 Lab 8 Fall 2007 Name: ________________________________________________ For the first problem, you will be making some observations of the running of a program, both the output and using debug for the values of variables. Please write down your observations on this lab sheet as indicated. 1. Practicing if statements. A. The following is a program to compute grades, GradeAverage.c. /* GradeAverage.c */ /* This program computes the average of a number of grades, and detects how many * were failing. Grades range from 0 to 100, and below 65 is failing. * This program uses a for loop with an if-then statement. */ #include <stdio.h> int main() { int grade = 0; /* input grade */ int index, numgrades; int gradetotal; /* the sum of all grades so far */ double average; /* compute the average of all grades */ int failurecount = 0; /* keep track of number of failing grades */ /* Give instructions to the user */ printf("Type in the number of grades to be entered (integers between 0 and 100)> \n"); scanf("%i", &numgrades); printf("\n"); /* initialize the total */ gradetotal = 0; for (index = 1; index <= numgrades; index++) { /* Get the input grade */ printf("Give the next grade> "); scanf("%i", &grade); /* add all the grades */ gradetotal = gradetotal + grade; /* test for and count the number of failing grades */ if (grade < 65) { failurecount++; } printf("\n"); } /* compute the average of the grades */ /* use a cast (conversion to a type) to make sure the division is not integer */ average = (double)gradetotal / numgrades; /* give the results */ /* the .2 says to print only 2 digits after the decimal point */ printf("Grade average = %.2lf \n", average); printf("Number of failures = %i \n", failurecount); return(0); } i. Cut and paste this program from the Lecture/Lab page. Run the program with 5 grades. What is the output? ii. Now step through the program using Debug | Step Into and Step Over and enter 5 grades where 3 of them are above 65 and two of them are below 65. Record the values of the variables as they are modified in the program. Variable Value1 Value2 Value3 …