hw - { int side; cout << "Enter a number:...

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

View Full Document Right Arrow Icon
Alan Hwang CS 31 Disc 1J HW 2 1. This input will give: endlendl grendel 2. This code will prompt the terminal to ask you for a number. If you type a negative number or zero, nothing happens. If you type an integer, it prints a “#” on a new line until the number of “#” equals the inputted variable. 3. #include <iostream> using namespace std; int main() { int side; cout << "Enter a number: "; cin >> side; int i = 0; for (int i = 0; i < side; i++) { int j = 0; while (j <= i) { cout << '#'; j++; } cout << endl; } } 4. #include <iostream> using namespace std; int main()
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { int side; cout << "Enter a number: "; cin >> side; int i = 0; if (side > 0) { do { int j = 0; while (j <= i) { cout << '#'; j++; } cout << endl; i++; } while (i < side); } } 5. #include <iostream> using namespace std; int main () { int month; cout << "What month is it? "; cin >> month; switch (month) { case 3: cout << "solstice" << endl; break; case 6: cout << "summer solstice" << endl; break; case 12: cout << "winter solstice" << endl; break; default: cout << "nothing special" << endl; break; } return 0; }...
View Full Document

This note was uploaded on 11/10/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 2

hw - { int side; cout << "Enter a number:...

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

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