Hello I've written a little console game and I'm wondering how I get the output to stay at a set position, as you will se from the output, the output is slightly shifting to the left as the game goes on, I want the text that is after the ||||| signs to be at a fixed position and should not be depending on wether how many || that is printed.
You can set the width of each output by using std::setw (#include <iomanip>).
This will output "Aktuell hög:" padded with space so that the output is exactly 16 characters. This is useful because we know that the next output will start at position 16. std::left is used to make the text left aligned.
cout << '\n' << setw(16) << left << "Aktuell hög:";
To output the sticks with std::setw you will have to output all the sticks at the same time. You can easily do this by adding the sticks to a std::string variable that you output at the end.
1 2 3 4 5 6 7 8 9
for (int i = 0; i < sticks; i++)
if ((i % 5) == 4)
str += "| ";
str += "|";
cout << setw(30) << left << str;
You don't need to use std::setw when outputting the question unless you want the user input to line up as well.
Now do the same with the "Resultat" row. You don't have to use the same values with setw that I did but make sure you use the same values for both rows, except you might have to use a value that is one larger when outputting "Aktuell hög:" because 'ö' is actually stored and counted as two characters (bytes).