I am just writing a mess around program and I am having troubles trying to figure out how to program the 'OK' button on a dialog box to display another dialog box that prompts the user whether to click 'Okay' to show that the user clicked okay, or when the user clicks 'Cancel' that it will end the program.
I have another program which asks the user a series of questions. I am trying to make it that if the user enters a number when the program asks to enter the user's name that it wont continue with the program unless the user enters a valid name and that if the user keeps inputting numbers instead of letters, that the program will loop until the user enters the correct input. The code is posted below.
I got a job at a high profile company and my position involves a lot of programming and I am willing to do anything to become amazing at programming. I am a beginner just for your information.
#include <iostream>
#include <windows.h>
usingnamespace std;
int secondBox();
int main(int argc, char *argv[])
{
int result;
int secondBox;
result = MessageBox(NULL, "Hello world! \nThis is the second line.", "Hello", MB_OKCANCEL);
if (result == IDOK) {
cout << "You clicked okay!\n";
cin >> secondBox;
}
else {
cout << "You clicked cancel!\n";
cout << "Thank you for using this program!\n";
}
cin.get();
return 0;
}
int secondBox(int argc, char *argv[])
{
int result;
result = MessageBox(NULL, "You clicked okay. Good job! \nClick 'Okay' for a different window. \nClick 'Cancel' to end the program.", "The Okay Box", MB_OKCANCEL);
if (result == IDOK) {
cout << "You clicked okay!\n";
}
else {
cout << "You clicked cancel!\n";
}
cin.get();
return 0;
}
Program that asks the user a bunch of questions (not completed):
#include <iostream>
#include <string>
usingnamespace std;
char chr;
int main()
{
//Declaring variables
int age;
string name;
cout << "Hello person, welcome to my program!\n";
cout << "I will ask you a series of questions\n";
cout << "and you must answer all of them.";
cout << "\n____________________________________\n";
cin.ignore();
//Asking for your name.
cout << "I will need your name before I start\n";
cout << "asking you questions. So... name please?\n";
cin >> name;
cout << "Thank you for entering your name " << name << ".\n";
//Asking for your age.
cout << "\n";
cout << "Now please enter your age: \n";
cin >> age;
if (age < 100) {
cout << "Wow, you are young!\n";
}
elseif (age == 100) {
cout << "You are pretty old.\n";
}
else {
cout << "You're probably not that old...\n";
}
return 0;
}