My code after finishing the if and else statements lesson

#include

int main()

{

//print 

std::cout << "Greetings traveller, so you have come for the riddle? ";

std::cout << std::endl;

std::cout << "It is a tricky one indeed, come forth and I shall grant you a chance at it";



const int CodeA = 4;

const int CodeB = 3;

const int CodeC = 2;



const int CodeProduct = CodeA * CodeB * CodeC;

const int CodeSum = CodeA + CodeB + CodeC;

std::cout << std::endl;

std::cout << "There are three numbers in the code" << std::endl;

std::cout << "The codes add-up to: " << CodeSum << std::endl;

std::cout <<"the codes multiply to give: " << CodeProduct << std::endl;

int GuessA, GuessB, GuessC;

std::cin >> GuessA;

std::cin >> GuessB;

std::cin >> GuessC;

std:: << "You entered: " << GuessA << GuessB << GuessC;

int GuessSum = GuessA + GuessB + GuessC;

int GuessProduct = GuessA* GuessB * GuessC;



if (GuessSum == CodeSum && GuessProduct == CodeProduct);

{

    std:: << "You Win traveller, congratulations";

}



else

{

    std:: << "NO! You are banished from these realms!";

}

return 0;

}


Here is my code after implementing the if else control block


Here is my code!

#include

int main()

{

//welcome message for game

std::cout << std::endl;

std::cout <<"You are a robber on a robbery scene and want to break the vault to steal a DIAMOND";

std::cout << std::endl;

std::cout <<"Your only way to open the vault is by feeding a correct code";



// declarations

const int CodeX = 3; 

const int CodeY = 5;

const int CodeZ = 1;



const int CodeSum = CodeX + CodeY + CodeZ;

const int CodeProduct= CodeX * CodeY * CodeZ;



// game start messages

std::cout << std::endl << std::endl;

std::cout << "Enter 3 digit code to get access" << std::endl; 

std::cout << "whose sum of number is " << CodeSum << std::endl;    

std::cout << "while product is " << CodeProduct << std::endl << std::endl;

std::cout << "Enter the code now and press 'Enter' ";

std::cout << std::endl;

//guessing the code

int GuessX, GuessY, GuessZ;     

std::cin >> GuessX;

std::cin >> GuessY;

std::cin >> GuessZ; 

std::cout << "You entered " << GuessX << GuessY << GuessZ;

int GuessSum = GuessX + GuessY + GuessZ;

int GuessProduct = GuessX * GuessY * GuessZ; 

std::cout << std::endl;

if (GuessSum == CodeSum && GuessProduct == CodeProduct) {

    std::cout << "You are smart";

}

else

{

     std::cout << "You cant steal like that...Go Away";

}    



return 0;

}


int main() {
    //Print welcomme messages
    std::cout << "You are in the dungeon. There is a locked door in front of you." << std::endl;
    std::cout << "The door opens with 3-number code." << std::endl;
    
    //Declare 3 number code
    const int CodeA = 2;
    const int CodeB = 3;
    const int CodeC = 4;

    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    // Print sum and product to the terminal
    std::cout << "Someone left you some hints." << std::endl;
    std::cout << "The codes add-up to: \t\t" << CodeSum << std::endl;
    std::cout << "The codes multiply to give: \t" << CodeProduct << std::endl;

    //Player guess declaration
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA >> GuessB >> GuessC;
    std::cout << "You entered: \t" << GuessA << ' ' << GuessB << ' ' << GuessC << std::endl;

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    //Checking answer
    if(GuessSum == CodeSum && GuessProduct == CodeProduct)
        std::cout << "The door opens loudly, and you continue your descent." << std:: endl;
    else
        std::cout << "BOOOOOOOOM. The lock explodes. You are trapped int the dungeon." << std::endl;
    return 0;
}
#include <iostream>

int main()
{
    // Print welcome messages to the terminal
    std::cout << std::endl << "You went exploring a haunted house, when someone knocked you out cold.......";
    std::cout << std::endl;
    std::cout << "Enter the correct codes to get out in time...alive...." << std::endl;

    // Declare 3 number code
    const int CodeA = 4;
    const int CodeB = 3;
    const int CodeC = 2;

    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    // Print CodeSum and CodeProduct to the terminal
    std::cout << std::endl;
    std::cout << "The spirit helping you gives you the following clues that.. 'it' ..has figured out over the years: " << std::endl << "+ There are three numbers in the code" << std::endl;
    std::cout << "+ The codes add-up to: " << CodeSum << std::endl;
    std::cout << "+ The codes multiply to give: " << CodeProduct << std::endl;

    int GuessA, GuessB, GuessC;
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "The good part is that you got the code correct, and no one noticed you!" << std::endl << "The sad part is that you found another door in front of you..." << std::endl;
    }
    else 
    {
        std::cout << "You got it wrong, the sprits catch you trying to escape and you died horribly!" << std::endl;
    }

    return 0;
}
1 Like

Keep it up everyone! :+1:

Heres my code so far!

heres mine

#include <iostream>

int main(){

    //misc var initialization

    const char CodePerEndl[100] = "********************************************************************";

    //introduction

    std::cout<<"You are lockpicking a door rigth now";
    std::cout<<std::endl;
    std::cout<<"Now you must open the door guessing the combination" <<std::endl;
    std::cout<<std::endl;
    std::cout<< CodePerEndl <<std::endl;
    std::cout<<std::endl;

    //other variables initialization

    int CodeA = 4;
    int CodeB = 5;
    int CodeC = 6;
    
    //sumarize var declaration

    int CodeSum = CodeA * CodeB * CodeC;

    //hint

    std::cout<<"You see in the walls some kind of ancient scripts...";
    std::cout<<std::endl;
    std::cout<<"the scripts says: " << CodeSum <<std::endl;
    std::cout<<"what if the numbers of the scripts are mutiplied?" <<std::endl;
    std::cout<<"seems like a hint..." <<std::endl;
    std::cout<<std::endl;
    
    //guess variable initialization

    int GuessA;
    int GuessB;
    int GuessC;
    
    //guessing the door

    std::cout<<"lets see: " <<std::endl;
    std::cout<<std::endl;

    std::cin>> GuessA;
    std::cin>> GuessB;
    std::cin>> GuessC;

    int GuessPro;
    GuessPro = CodeA + CodeB + CodeC;

    int GuessSum;
    GuessSum = GuessA + GuessB + GuessC; 

    //win or lose denpending on the guess

    if(GuessPro == GuessSum){ //win

        std::cout<<"*Congratulations*" <<std::endl;
        std::cout<<std::endl;
        std::cout<<"That was easy" <<std::endl;
        std::cout<<"lets move into the next room";
        std::cout<<std::endl;
        std::cout<<std::endl;
        std::cout<< CodePerEndl <<std::endl;
        std::cout<< std::endl;

    }
    else{ //lose

        std::cout<< CodePerEndl <<std::endl;
        std::cout<< std::endl;
        std::cout<<"pfff lets try again" <<std::endl;
        std::cout<<std::endl;
        std::cout<< CodePerEndl <<std::endl;
        std::cout<< std::endl;
    }
    
   return 0;

};

(inglish is not my native lenguaje)

Here is what I wrote.

#include

int main()

{

// printing welcome messeges to the terminal

std::cout << "you are in a number guessing game....";

std::cout << std::endl;

std::cout << "enter the code successfully to progress onto further levels. GOOD LUCK!";

const int CodeA = 5;

const int CodeB = 2;

const int CodeC = 2;

const int CodeSum = CodeA + CodeB + CodeC;

const int CodeProduct = CodeA * CodeB * CodeC;

std::cout << std::endl;

std::cout << std::endl;

// printing sum and product

std::cout << std::endl << "There are three numbers in the code.";

std::cout << std::endl << "They add-up to : " << CodeSum;

std::cout << std::endl << "Their product is : " << CodeProduct;

std::cout << std::endl;

int GuessA, GuessB, GuessC;

int Count = 0;

std::cout << "Enter your guess : ";

std::cin >> GuessA >> GuessB >> GuessC;

std::cout << std::endl;

int GuessSum = GuessA + GuessB + GuessC;

int GuessProduct = GuessA * GuessB * GuessC;



if(CodeSum == GuessSum && CodeProduct == GuessProduct)

{

    std::cout << "You are correct.";

}

else

{

    std::cout << "You are wrong.";

}



return 0;

}

Here is my code after this lesson :smile:

#include <iostream>

int main()
{    
    // Print welcome messages to the terminal
    std::cout << "Greetings Agent X," << std::endl;
    std::cout << "We have a suspicion that one of the laboratories in north is developing a new deathly diseases to use it as a bio weapon." << std::endl;
    std::cout << "Your job is to break into the laboratory and get the necessary evidence so that we can expose their intestions." << std::endl;
    std::cout << std::endl;
    std::cout << "...time skip...";
    std::cout << std::endl;

    // Declare 3 number code
    const int CodeA = 7;
    const int CodeB = 3;
    const int CodeC = 1;

    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    // Print CodeSum and CodeProduct to the terminal
    std::cout << std::endl;
    std::cout << "You have successfully got inside the laboratory but there is a safe with combination lock infront of you." << std::endl;
    std::cout << "There are three numbers in the code" << std::endl;
    std::cout << std::endl;
    std::cout << "The codes add-up to: " << CodeSum << std::endl;
    std::cout << "The codes multiply to: " << CodeProduct << std::endl;

    int GuessA, GuessB, GuessC;
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << "You got all the evidence. Good job, Agent X.";
    }

    else
    {
        std::cout << "You failed your mission, Agent X. The laboratory has used a new bio weapon.";
    }
    

    return 0;
}
//preprocessor Directive
 /****** Instruction to the complier
    #include <iostream>
    <iostream> = header file that contains code
    this compiles the header file code first then ours
********/
/***++++++====Unreal USES UPPER CAMEL CASE====+++++***/
#include <iostream>

int main() { //int main function; it is the entry point of our program

    //printing starting messages here
    std::cout << std::endl;
    //cout means character output
    std::cout << "\n";
    std::cout << "You are the inceptor and you need to break into someones mind vault...you only have one chance.";
    std::cout << std::endl;
    
    std::cout << "You must figure out what numerical value is significant to the subject...";
    std::cout << std::endl;
    
    //declared 3 number codes; keys to winning
    const int CodeA = 7;
    const int CodeB = 9;
    const int CodeC = 2;

   // Totals for the Sum and Product
    const int MemorySum = CodeA + CodeB+ CodeC;
    const int MemoryProduct = CodeA * CodeB * CodeC;

    std::cout << "\n";
    std::cout << "There are 3 numbers you must use to unlock the first memory" << std::endl;
    std::cout << "The memory recalls a total of " << MemorySum << " and, " << std::endl;
    std::cout << "the synapses recollect a multiplied value of " << MemoryProduct << "!" << std::endl;
    
    std::cout << "\n";
    std::cout << "What three numbers are significant to the subject?" << std::endl;

    //Variables not initialized until the player guesses for each value in the console
    int GuessA, GuessB, GuessC;
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;
    std::cout<<std::endl;

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    if (GuessSum == MemorySum && GuessProduct == MemoryProduct) {
        std::cout<< "You have broke into the first mind vault. Congragulations, but this is only the begginning...";
        std::cout<<std::endl;

    } else {
        std::cout<< "You are lost in limbo...forever";
        std::cout<<std::endl;
    }

    return 0;
}


#include <iostream>

int main()
{
    // Print intro messages to the terminal.
    std::cout << std::endl;
    std::cout << "A locked door impedes your path towards escape." << std::endl;
    std::cout << "It is locked via a passcode..." << std::endl;
    std::cout << "If you can figure out the code, freedom is yours." << std::endl;

    // Declare 3-number code.
    const int CodeA = 4;
    const int CodeB = 6;
    const int CodeC = 8;

    const int CodeSum = CodeA + CodeB + CodeC;
    const int CodeProduct = CodeA * CodeB * CodeC;

    // Print sum and product to the terminal.
    std::cout << std::endl;
    std::cout << "* There are 3 numbers in the code." << std::endl;
    std::cout << "* These numbers add up to: " << CodeSum << std::endl;
    std::cout << "* And when multipled, give: " << CodeProduct << std::endl;

    // Declare the player's 3 guesses.
    int GuessA, GuessB, GuessC;

    // Write player input to guess variables.
    std::cin >> GuessA;
    std::cin >> GuessB;
    std::cin >> GuessC;

    int GuessSum = GuessA + GuessB + GuessC;
    int GuessProduct = GuessA * GuessB * GuessC;

    //Show win message if guesses are correct, lose message if they are not.
    if (GuessSum == CodeSum && GuessProduct == CodeProduct)
    {
        std::cout << std::endl;
        std::cout << "PASSCODE ACCEPTED. The door opens." << std::endl;
    }

    else
    {
        std::cout << std::endl;
        std::cout << "PASSCODE DENIED. ...You may be here a while." << std::endl;
    }

    return 0;
}

C O D E

3 4

Privacy & Terms