#include <iostream> 
#include <string>
using namespace std;
//text editors
string red ="\033[0;31m";
string green ="\033[1;32m";
string bold ="\x1B[1m";
string def_txt ="\x1B[0m";
string clrscrn ="\033[2J\033[1;1H";
bool valid (int a) {
    if (a==1 || a==2)
        return true;
    else 
        return false;
}
void ui_er() {
    cin.clear();
    cin.ignore();
    cout<<red<<"\nPlease enter a valid answer before you put yourself on the asshole list :')\n"<<def_txt;
}
void ui(int& a) {
    while (!(cin >> a) || !(valid(a)))
        ui_er();
}
int main () {
    int a1,a2,a3,a4;
    string ans = "\n 1 Yes 2 No\n";
    cout<< "\nDo you make uninformed decisions?";
    cout<< ans;
    ui(a1);
    cout << "\n Are you aware that those decisions are uninformed?";
    cout << ans;
    ui(a2);
    cout << "\n Do you put on an elaborate and distinctive act?";
    cout << ans;
    ui(a3);
    cout << "Do you know that this act harms you in some way and/or is absurd and meaningless?";
    cout << ans;
    ui(a4);
    bool fool, clown, clowna, foola, liar, confused, nihilist;
    if (a1==1) {
        fool=true;
        if (a2==1)
            foola=true;
    }
    if (a1==2 && a2==1) {
        confused=true;
    }
    if (a3==1) {
        clown=true;
        if (a4==1) 
            clowna=true;
    }
    if (a3==2 && a4==1) {
        nihilist=true;
    }
    cout <<clrscrn;
    if (nihilist==1)
        cout << "\nYou transcend reality. You have opened your third eye.";
    else if (confused==1) {
        cout << bold<< "\nYou are a crackhead and confused. Sober up and take the quiz again...";
        main();
    }else if (fool==1 && foola==0 && clown==0) 
        cout << "\nYou are a fool straight and simple.";
    else if (clown==1 && clowna==0 && fool==0) 
        cout << red << bold<<"\nYou are a clown. Wake up.";
    else if (clowna==1) 
        cout << red << bold<<"\nYou are a clown who is a fool.";
    else if(foola=1) 
        cout <<"\nYou are a fool that is a clown.";
} 

C++ Online Compiler

Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!

Read inputs from stdin

OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string name;
    cout << "Enter name:";
    getline (cin, name);
    cout << "Hello " << name;
    return 0;
}

About C++

C++ is a widely used middle-level programming language.

  • Supports different platforms like Windows, various Linux flavours, MacOS etc
  • C++ supports OOPS concepts like Inheritance, Polymorphism, Encapsulation and Abstraction.
  • Case-sensitive
  • C++ is a compiler based language
  • C++ supports structured programming language
  • C++ provides alot of inbuilt functions and also supports dynamic memory allocation.
  • Like C, C++ also allows you to play with memory using Pointers.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition If-Else is used.

if(conditional-expression) {
   //code
}
else {
   //code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression){    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
......    
    
default:     
 code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  //code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
// code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
 // code 
} while (condition); 

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.

How to declare a Function:

return_type function_name(parameters);

How to call a Function:

function_name (parameters)

How to define a Function:

return_type function_name(parameters) {  
 // code
}