CS100 HW6
CS100 HW6
1. (4 pts) Given a variable x. Show the four different ways that we can increment x by
1.
2. (1 pts) What would happen if we have the following while loop in our program?
while(true)
{
cout << "Hi";
}
3. (3 pts) Write a program which prints out letters ’K’ to ’R’. Use a while loop to
achieve it.
#include <iostream>
using namespace std;
int main()
{
for(int i=1; i<3; i++)
{
for(char j=’a’; j <= ’c’; j++)
{
cout << i << j << endl;
}
}
}
6. (5 pts) Write a program to calculate your GPA. The program will do the following.
1
CS 100 Bradley University Dept. of Computer Science &
Instructor: Tachun Lin Spring 2021 Information Systems
(a) Prompt the user how many courses/grades you would like to calculate.
(b) Use a loop (for or while) to accept the inputs of the grades.
(c) Sum up all the grades.
(d) Your GPA (based on the grades you enter) is calculated by