...

/

Build Your App

Build Your App

Build a full console application using multiple C++ concepts.

We’ll now build a complete Math Quiz App step by step, using functions to make our code cleaner and reusable. Each step adds one requirement and builds on top of the previous code.

Step 1: Ask the user for their name

Start by writing a function getUserName() that asks for the user’s name and returns it. This makes our code modular and reusable.

#include <iostream>
using namespace std;

// TODO: Define getUserName() function here

int main() {
    string name ; // TODO: Store the captured name in this variable
    return 0;
}
Ask the user for their name

If you’re stuck, click the “Show Solution” button.

Great! Your app can now ask for the user’s name and store it for later use.

Step 2: Show a personalized welcome message

Now, create a function showWelcome(name) that prints a personalized welcome message using the name we got from the previous step.

#include <iostream>
using namespace std;

string getUserName() {
    string name;
    cout << "Enter your name: ";
    cin >> name;
    return name;
}

// TODO: Define showWelcome(name) function here

int main() {
    string name = getUserName();      // Get user name
    
    // TODO: Call showWelcome(name) here
    
    return 0;
}
Print a personalized welcome message

If you’re stuck, click the “Show Solution” button.

Awesome! Your app now greets the user with a friendly, personalized welcome. ...

Step 3: Ask five math questions