Lab02_sample - " "...

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

View Full Document Right Arrow Icon
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; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 <<
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &quot; &quot; &lt;&lt; x + 2 &lt;&lt; endl; cout &lt;&lt; &quot; &quot; &lt;&lt; x + 3 &lt;&lt; &quot; &quot; &lt;&lt; x + 3 &lt;&lt; endl; cout &lt;&lt; x + 4 &lt;&lt; &quot; &quot; &lt;&lt; x + 4 &lt;&lt; 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 &lt;iostream&gt; using namespace std; int main() { int quaters, dimes, nickels, total; cout &lt;&lt; &quot;number of quaters? &quot; ; cin &gt;&gt; quaters; cout &lt;&lt; &quot;number of dimes? &quot; ; cin &gt;&gt; dimes; cout &lt;&lt; &quot;number of nickels? &quot; ; cin &gt;&gt; nickels; total = 25*quaters + 10*dimes + 5*nickels; cout &lt;&lt; &quot;total is &quot; &lt;&lt; total &lt;&lt; &quot; cents\n&quot; ; return 0; }...
View Full Document

This note was uploaded on 07/14/2008 for the course CMPSC 101 taught by Professor Drobish,renee during the Summer '07 term at Pennsylvania State University, University Park.

Page1 / 3

Lab02_sample - &amp;amp;quot; &amp;amp;quot;...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online