{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lab02_sample

# Lab02_sample - ""<< x 2<< endl...

This preview shows pages 1–3. Sign up to view the full content.

CMPSC 101 Introduction to Algorithmic Processes Summer 2007 LAB 2 – Simple C ++ Program 1. Write a program that asks the user to enter a number between 0 and 5. The program should then display the number in the following pattern. Enter a number between 0 and 5: 4 4 4 4 4 4 4 4 4 4 [sample code] #include <iostream> using namespace std; int main() { int x; cout << "Enter a number between 0 and 5: " ; cin >> x; cout << endl << endl; cout << x << " " << x << endl; cout << " " << x << " " << x << endl; cout << " " << x << endl; cout << " " << x << " " << x << endl; cout << x << " " << x << endl; return 0; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2. Modify your program to increase the numbers in each line by 1. Enter a number between 0 and 5: 4 4 4 5 5 6 7 7 8 8 [sample code] #include <iostream> using namespace std; int main() { int x; cout << "Enter a number between 0 and 5: " ; cin >> x; cout << endl << endl; cout << x << " " << x << endl; cout << " " << x + 1 << " " << x + 1 << endl; cout <<
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: " " << x + 2 << endl; cout << " " << x + 3 << " " << x + 3 << endl; cout << x + 4 << " " << x + 4 << endl; return 0; } 3. [text p.38] Write a program that allows the user to enter a number of quarters, dimes, and nickels and then outputs the monetary value of the coins in cents. For example, if the user enters 2 for the number of quarters, 3 for the number of dimes, and 1 for the number of nickels, then the program should output that the coins are worth 85 cents. [sample code] #include <iostream> using namespace std; int main() { int quaters, dimes, nickels, total; cout << "number of quaters? " ; cin >> quaters; cout << "number of dimes? " ; cin >> dimes; cout << "number of nickels? " ; cin >> nickels; total = 25*quaters + 10*dimes + 5*nickels; cout << "total is " << total << " cents\n" ; return 0; }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

Lab02_sample - ""<< x 2<< endl...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online