+ 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
6 Antworten
+ 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. :>
+ 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;
}
+ 5
Add this to your example, after taking input:
if(a > 18)
{
// do stuff
}
else
{
// do other stuff
}
+ 5
That bool seems redundant Hasty 😜
+ 2
hehe thx, i still have a long way to go
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;
}