How to use IF statements C++. To make a menu choice, we need an IF statement. This statement is used to solve the problem in making a decision among all these existing conditions. Sintax like this:
if (condition)
{
statement;
}
IF statements ELSE statements can also be added as an alternative if the condition is not fulfilled .. Sintaxnya:
if (condition)
statement_1;
else
statement_2;
In the program menu of options that we use this time, the IF statement is used to select one of the selected menu .. example, if we choose a menu, it will start a new game (New Game) .. if you select menu 2, then it will start a saved game (Load Game), if you select menu 3, it will come out of the game (Exit) ..
In the program, source code would be like this ..
#include <iostream>
using namespace std;
void main()
{
int a;
int b;
int c;
int d;
int e;
int f;
int g;
cout << "Enter Fist Number: ";
cin >> a;
//cout << a << "\n";
cout << "Enter Second Number: ";
cin >> b;
//cout << a << "\n";
cout << "Enter Next Number: ";
cin >> c;
//cout << a << "\n";
cout << "Enter Next Number: ";
cin >> d;
//cout << a << "\n";
cout << "Enter Next Number: ";
cin >> e;
//cout << a << "\n";
cout << "Enter Next Number: ";
cin >> f;
//cout << a << "\n";
cout << "Enter Next Number: ";
cin >> g;
//cout << a << "\n";
if (a=b=c=d=e=f=g)
{
"Cannot Enter Same Numbers! ";
}
}
thanks
Friday, 21 October 2011
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment