View Full Version: How to do things in C++ Part 2

C++ Learning Community > C++ Tips > How to do things in C++ Part 2


Title: How to do things in C++ Part 2


Dragon - June 23, 2003 05:05 AM (GMT)
Here's another program. Besides teaching the stuff showed in my other post, it teaches how to display Windows message boxes and how to use "if" and "else." There are no comments, so if you have any questions you can post them and I'll try to answer them.

#include <iostream>
#include <windows.h>

using namespace std;

#define MSG(msgtext, msgcap) \
MessageBox(GetActiveWindow(),msgtext,msgcap,MB_OK);

int Display()
{
int val1, val2;
MSG("Welcome to this program!","Welcome");
cout << "Enter an integer between 1 and 10:" << endl;
cin >> val1;
if (val1 < 1 || val1 > 10 || val1 == 1 || val1 == 10)
{
MSG("You must enter a number between 1 and 10!","Error");
}
else
{
cout << "Enter another integer between 1 and 10:" << endl;
cin >> val2;
if (val2 < 1 || val2 > 10 || val2 == 1 || val2 == 10)
{
MSG("You must enter a number between 1 and 10!","Error");
}
else
{
cout << "First integer: " << val1 << "\n" << "Second integer: " << val2 << endl;
}
}
system("PAUSE");
}

int main()
{
Display();
}




* Hosted for free by InvisionFree