Hello there! I suggest you to have a look at the following program. Run it, read its code, and see how you could replicate the same, "nice, readable" stdout
output!
Also, please do not use numbers to ask users for navigating menus! You might want to make use of actual words, and check if they are equal to a string without caring about the case. Put the entire query into a function so you can repeat it if the user enters something wrong. Also, do not perform checks on the input in the same function that also gives the user these options! Use another function for it. That way, you will be able to repeat certain tasks easily.
You might want to make functions to, say, print lists, simple lines, et cetera, then use those throughout the program along with separate functions to check the user's input. This will make things easier! Using function pointers here will give you extra convenience.
Feel free to ask me for example code doing this stuff!
#include <iostream>
#include <thread>
#include <chrono>
#pragma region // Header definitions!
#define ORIGINAL_WRITING_DELAY 50;
template <typename T>
void print(T);
void sleep(long);
void write(std::string);
#pragma endregion
namespace Speed {
// This `static` limits these variables to this
// "translation unit" (`.h` and `.cpp` combination.)
/* static */ long LETTER, COMMA, FULLSTOP, EXCLAIM;
void reset()
{
LETTER = ORIGINAL_WRITING_DELAY;
COMMA = 4 * LETTER;
FULLSTOP = 10 * LETTER;
EXCLAIM = 6 * LETTER;
}
void setDelay(const long p_to)
{
LETTER = p_to;
COMMA = p_to * 4.0f;
FULLSTOP = p_to * 10.0f;
EXCLAIM = p_to * 6.0f;
}
}
int main(const int p_argCount, char const *p_arrArgValues[]) {
Speed::reset();
printf("Yo, I'm here simply waiting for you to press Enter.");
std::cin.ignore();
write("Hello, World!\a");
}
template <typename T>
void print(T p_toOutput) {
std::cout << p_toOutput << '\n';
}
void sleep(const long p_time) {
std::this_thread::sleep_for(std::chrono::milliseconds(p_time));
}
void write(const std::string p_str) {
char c;
const unsigned int length = p_str.length();
for (unsigned int i = 0; i < length; i++) {
using namespace std;
c = p_str.at(i);
cout << c;
cout.flush();
using namespace Speed;
// Sleep for some time, based on the character encountered:
switch (c) {
case ',':
sleep(COMMA);
break;
case '.':
sleep(FULLSTOP);
break;
case '!':
sleep(EXCLAIM);
break;
default:
sleep(LETTER);
}
}
std::cout << '\n';
}