+ 1

cin and if else combo

enter a number and get if/else statement working like following > if 18+ go forward else block page (for example) anyone got an idea? #include <iostream> using namespace std; { int a; cout << "Please enter your age\n"; cin >> a; cout << a; return 0; } thanks and keep it simple

14th May 2017, 8:02 PM
Marlon De Gang
Marlon De Gang - avatar
6 Answers
+ 12
@Rrestoring faith I'm just gonna pull off one of those "If you're working on a huge project" lines and try to get out of here. :>
14th May 2017, 9:01 PM
Hatsy Rei
Hatsy Rei - avatar
+ 11
#include <iostream> using namespace std; int main() { int age; bool access; cout << "Please anter your age : "; cin >> age; age >= 18 ? access = true : access = false; if (access) { cout << "Lewd stuff now availble. :>"; } else { cout << "Too young for this, boy."; } return 0; }
14th May 2017, 8:48 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Add this to your example, after taking input: if(a > 18) { // do stuff } else { // do other stuff }
14th May 2017, 8:11 PM
Rrestoring faith
Rrestoring faith - avatar
+ 5
That bool seems redundant Hasty 😜
14th May 2017, 8:59 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
hehe thx, i still have a long way to go
14th May 2017, 8:50 PM
Marlon De Gang
Marlon De Gang - avatar
0
#include <iostream> using namespace std; { int a; cout << "Please anter your age\n" cin << a; if ( a > 18) { cout << "Acces granted\n" <<endl; } else { cout << "acces denied"\n <<endl; return 0; }
14th May 2017, 8:23 PM
Marlon De Gang
Marlon De Gang - avatar