Making a simple interactive win32 console message

Hey,

So I have been looking into c++ a bit now, been very interested in programming for years and have friends with limited experience.

I started learning the basics yesterday (I already had good basic knowledge of what programming is and how programming languages work, and I know how variables etc work so I feel I have a good base knowledge to start learning) I already got down the "hello world" and how to create variables with integers and make simple messages, I also have learned how to make loop codes like:


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
#include <iostream>

using namespace std;

void main()
{
	int svar;

	cout << "Type in a number from 1-3 for a response. Type 0 to exit." <<endl;
	cin >> svar;

	while( svar != 0 )
	{
		if ( svar == 1 )
		{
			cout << "Lol noob" << endl;
		}
		else if( svar == 2 )
		{
			cout << "kek bur" << endl;
		}
		else if ( svar == 3 )
		{
			cout << "Ouch" << endl;
		}
		else if( svar > 3 )
		{
			cout << "You must type a number between 1 and 3" << endl;
		}

		cout << "Type another number: ";
		cin >> svar;
	}
}




Now I wanted to make something a bit more complex, but this is where my friends knowledge ran out and I have been searching the internet for this for hours now (also how I haply ran into these forums)

So here is what I want to make:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
You get a start up text that says something, lets say:

"Welcome to this message, please type y to continue or n to close this program"

the user presses y and the next message pops up and the old one is removed

"You have chosen to move on in the message, would you like to continue y/n"

The user presses y to continue or n to close the program

"This is the next message, would you like to continue y/n"


etc etc

and then eventually I want to learn how to make the messages branch out with multiple choices but I figured this was a good start, any comments are greatly appreciated on how I can get this done !

Thank you all !

It's int main(), not void.

Unfortunately, the console is not really meant to do things like clear itself, print on specific lines, etc. If you really want to do that, you could look into the ncurses library.

Otherwise, I would suggest just doing it without clearing the screen...btw if you need a good tutorial, this site has quite a nice one:
http://www.cplusplus.com/doc/tutorial/
Last edited on
Thanks !

its fine if it cant clear the lines, that would have just been more "neat" for the user :) thanks for the link I will check it out !
Awesome, thanks a lot man !

I read the tutorial and it solved my problem and Im now able to make the code, and I can use

system("cls");

to clear the previous message

so taken from the tutorial and adding the system("cls");

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string mystr;
  cout << "What's your name? ";
  getline (cin, mystr);
  system("cls");
  cout << "Hello " << mystr << ".\n";
  cout << "What is your favorite team? ";
  getline (cin, mystr);
  system("cls");
  cout << "I like " << mystr << " too!\n";
  cin.get();
  return 0;
}
Last edited on
I would suggest you to *not* use system(). Check here for why:

http://www.cplusplus.com/forum/articles/11153/
Topic archived. No new replies allowed.