Intro C++ formatting help!




I have posted a small part of my code for what I need help on. I am in an intro to C++ class right now and I have to ask the user for the number of tickets and output it to the screen. I have done everything else. The only part I can't get right is formatting when I ask the user to "enter the # of class A tickets sold: "
My professor loves for us to format it to about the center of the screen so it looks nice. But when I try and format it, I can't get it into the center of the screen the way I want. I can only format it to where I push it down to the bottom of the screen and then after that I have formatted the code so the next output to the screen appears in the center (I did not include that part of my code). I am just so confused on how to get it into the center of the screen where I can ask the user to input it instead of the bottom of the screen. Any help on this would be so much appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main()
{
    const double TAX_RATE = .075;
    const int CLASS_A = 15, CLASS_B = 12, CLASS_C = 9;
    int classA, classB, classC;
    double subTotal, total, tax;
    double totalClassA, totalClassB, totalClassC;

    //function call
    splash();
    welcome();

    cout << "\n\n\n\n\n\n\n\n\n\n";
    cout << setw(56) << "Enter the # of class A tickets sold: ";
    cin >> classA;
    cout << setw(56) << "Enter the # of class B tickets sold: ";
    cin >> classB;
    cout << setw(56) << "Enter the # of Class C tickets sold: ";
    cin >> classC;
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
You might try the following windows only solution to manipulate the screen position in a console window:
1
2
3
4
5
6
7
8
9
10
11
 
#include <windows.h>

void gotoXY(int x, int y) 
{   HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD CursorPosition;

    CursorPosition.X = x; // Locates column
    CursorPosition.Y = y; // Locates Row
    SetConsoleCursorPosition(console,CursorPosition); // Sets position for next thing to be printed 
}

Topic archived. No new replies allowed.