Skip to content

Instantly share code, notes, and snippets.

@itsjohncs
Forked from paranoiacblack/input1.txt
Last active December 24, 2015 21:19
Show Gist options
  • Save itsjohncs/6864491 to your computer and use it in GitHub Desktop.
Save itsjohncs/6864491 to your computer and use it in GitHub Desktop.
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;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment