11 Sep 2018

Instructions

  • Open the repl.it C++ template in a new browser tab (Middle Click).

    • Click the fork button on the top of the page.

    • You now have a private copy of the template. Copy and save the new URL.

  • Before you submit your work, spend 3-4 minutes discussing your solution with other students at your table.

  • Please submit your work via submission form (one per person).

Chunk 1: Processing Input

  • Compile and run the following chunk.

    • Test and verify its output.

// Input
#include <iostream>
#include <string>
int main()
{
  using std::cout;
  using std::string;

  // Define some variables
  string name
  uint name_length;

  // Prompt the user:
  cout << "Please enter your first name and hit enter: \n";
  cin >> name;

  name_length = name.size();
  cout << "Your name is " << name << ", which contains " << name_length << " letters.\n";
}

Chunk 2: Your Turn

Note: You may find the following reference helpful * LearnCpp: If Statements

Instructions

  • Using the above chunk as a template.

  • Ask the user their name, and quest.

    • Use cin to store each response in a separate variable.

  • Store the length of each response (as above).

  • Use an if () statement to compare the length of the name to the quest.

    • If the quest is shorter than the name, tell the user they succeed.

    • Otherwise, they fail.

  • Test the code using your name, and different quests.

Bonus Problem:

  • In Chunk 2, what happens if you compare the responses themselves (i.e., the strings), rather than their lengths?

  • Provide comments explaining what’s happening.