TripleX level difficulty to state ordinal numbers

Hello, I am a fresh beginner to C++ and wrote a story to my triple X game to reflect a haunted mansion theme.


I’ve written my code to state the player is on (number) floor of the mansion, but a better way to put it would be “You are on the 1st/2nd/3rd floor”. Is there a way to increase the level difficulty using ordinal numbers?
Below I have all of the code I have written thus far. (I am on Lesson 28 Function Parameters).

Could write a function. Would need to introduce std::string which hasn’t been taught .

#include <string>

std::string GetOrdinal(int Value)
{
    switch (Value)
    {
    case 1:
        return "first";
    case 2:
        return "second";
    case 3:
        return "third";
    default:
        return "unknown";
    }
}

A switch statement is like a series of if's. More info on them:
https://en.cppreference.com/w/cpp/language/switch

Thanks,
For what I understand about #include , #include is pulling from a different library?

I wrote the function under iostream like this:

#include <iostream>

#include <string>

std::string GetOrdinal(int Value)

{

    switch (Value)

    {

    case 1:

        return "first";

    case 2:

        return "second";

    case 3:

        return "third";

    default:

        return "unknown";

    }

}

And then in PrintIntroduction I put:

std:: cout << "You are trapped inside a haunted mansion. You find yourself locked inside a room on the " <<GetOrdinal(Difficulty);

 std::cout << " floor.\n\n";

It seems to work!

Sorry for formatting issues, I dont quite understand how the forum formats just yet. I have a screenshot for clarity

You can indent by 4, surround with 3 backticks like so

```
code goes here
```

Or use the </> button.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms