Skip to content

Instantly share code, notes, and snippets.

@paranoiacblack
Forked from itsjohncs/input1.txt
Created October 10, 2012 16:26
Show Gist options
  • Save paranoiacblack/3866704 to your computer and use it in GitHub Desktop.
Save paranoiacblack/3866704 to your computer and use it in GitHub Desktop.
CS 10 SI Classroom Session 2 - Example 1
Twix
Fido
John
Smith
47
Skittles
Hammy
Daniel
de Haas
20
Starburst Starla Sarah Fredrickson 82
// Including iostream for access to cout, cin, and string
#include <iostream>
// Clarifying which namespace to get cout, cin, and string from.
using namespace std;
int main() {
// Variables are uninitialized because we will get initial input from user.
string faveCandy;
string firstPet;
string firstName;
string lastName;
int age;
// Question: what are the values of the above variables?
// User prompts for initializing variables
// Notice how they are in blocks that make them logically distinguishable.
cout << "Enter your favorite candy: ";
cin >> faveCandy;
cout << "Enter the name of your first pet: ";
cin >> firstPet;
cout << "Enter your first and last name: ";
// Similar to cout, cin can be chained together to read in multiple inputs
// at once.
cin >> firstName >> lastName;
cout << "Enter your age: ";
cin >> age;
// Display entered information to user in interesting way.
cout << endl;
cout << "Your name is " << firstName << " " << lastName
<< " and your first pet's name was " << firstPet
<< " and your favorite candy is " << faveCandy << " and you are "
<< age << " years old." << endl;
/* We return 0 here to say the program ran successfully, but can you come up
with a set of input that wouldn't mean the program was successful?
(HINT:) Mr. Miller spent a fair amount of time on this idea in class. */
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment