Structured Programming in C++
Prof. Gregory Safko

Camden County College, Cherry Hill Campus

Lab 3

 


1. Printing a character in a loop (charloop.cpp)

Write a program that asks the user for a symbol (using a variable of type char, rather than of type int or double) and a number of copies to print, and prints a line of that many copies of that symbol.

(If the user enters an integer less than 1 for the number of copies to print, a properly written loop will iterate zero times, and not print out any symbols. For this lab problem, this behavior is fine; there is no need for additional error checking.)

Here is one possible output format:

What symbol would you like to print? b
How many copies? 6
bbbbbb
Press any key to continue
 

2. Counting up and down (countUpDown.cpp)

Write a program that asks the user for an integer, and counts up from 1 to that integer and then back down, with all the numbers on the same line.

The output should look exactly like mine, given the same input. Here are two example runs:

Enter an integer: 6
1 2 3 4 5 6 5 4 3 2 1 
Press any key to continue


 
 
Enter an integer: 1
1 
Press any key to continue

Hints: