erasing certain lines

I am making a program and i want it to show a number, and after a certain amount of seconds i want it to delete that line because its a memory game where it shows you a random number and then you have to remember what it was. Now, my program does all of that except delete the numbers, i was going to use sleep, and then system("cls") but that clears everything, is there a way to delete a certain line of code??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>
#include <ctime>
#include <random>
#include <windows.h>

using namespace std;

int main()
{
    int X;
    int type;
    int score = 0;
    int right = 0;
    int wrong = 0;

    time_t T;
    time(&T);
    srand(T);

    while(true)
    {

    for(int R = 0; R < 100; ++R)
    {
        X = rand() % 10000;
    }
        cout << "               " << "Score: " << score << endl;
        cout << "\n";
        cout << X << endl;
        cin >> type;

        if(type == X)
        {
            cout << "\n";
            cout << "Good!" << endl;
            score += 1;
            right += 1;
            cout << "\n";
        }
        else if(type != X)
        {
            cout << "\n";
            cout << "Wrong!" << endl;
            score -= 1;
            wrong += 1;
            cout << "\n";
        }
    }
}
You'd have to use OS-specific functions to do that...
...(or look into Curses or something like that)

Since I see you're using Windows, this might help:
http://msdn.microsoft.com/en-us/library/ms687410%28v=vs.85%29.aspx
@Ch1156

You could do it this way.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <string>
#include <ctime>
#include <windows.h>

using namespace std;

int main()
{
    int X;
    int type;
    int score = 0;
    int right = 0;
    int wrong = 0;

    time_t T;
    time(&T);
    srand(T);

    while(true)
    {
    for(int R = 0; R < 100; ++R)
    {
        X = rand() % 10000;
    }
        cout << "               " << "Score: " << score << endl;
        cout << "\n";
        cout << X;
		Sleep(2000);
		cout << "\b\b\b\b     \nEnter the number. : ";  // \b is a backspace. So four backspaces start at beginning of numbers, then the four spaces, deletes the numbers shown.
// Adjust the 2000, to amount of time needed
        cin >> type;

        if(type == X)
        {
            cout << "\n";
            cout << "Good!" << endl;
            score += 1;
            right += 1;
            cout << "\n";
        }
        else if(type != X)
        {
            cout << "\n";
            cout << "Wrong!" << endl;
            score -= 1;
            wrong += 1;
            cout << "\n";
        }
    }
}
this is hard to do because c++ was not built to be consul dependent and relies mainly on a GUI program to do things like this. there are system commands that might do this but it is a bad habit to get into.
Topic archived. No new replies allowed.