Jump to content

[Tut]C++ Truth, branching and other game loop: Guess my number


Recommended Posts

Posted

Well recently i started reading e-books about C++.

I started making mini and easy programs and im still on start but i think im gonna be way better on next days.

 

So, here's a tutorial about a score rater, running on cmd.

 

First of all u need to have a C++ application. Im using CodeBlocks, since i got some problems on Microsoft Visual ++ 2008.

 

Anyway, lets start.

 

Make a CLEAN project from file > new > project.

 

After this start making your program.

 

//Score Rater

 

#include <iostream>

using namespace std;

 

int main()

{

   int score;

   cout << "Enter your score: ";

   cin >> score;

 

   if (score > 500)

       cout << "\nYou got over 500. Nice score.\n";

   else

       cout <<"\nYou got 500 or less. Nothing to brag about.\n";

 

   return 0;

}

 

 

 

 

If score is greater than 500, the message you got over 500... is displayed.

 

   if (score > 500)

       cout << "\nYou got over 500. Nice score.\n";

 

The else clause provides a statement for the program to branch to the if the condition is false. So if (score > 500) is false, then the program skips the first message and instead displays the message, You got 500 or less...

 

   else

       cout <<"\nYou got 500 or less. Nothing to brag about.\n";

 

Watch out, because an else clause associates with its nearest preceding if. This can lead to logical errors and unintended results if you are not careful. Here's a bit of new code (not part of the score rater program) to show you what i mean:

 

   if (false)

       if (true)

               cout << "This will never be displayed.";

   else

       cout << "This will always be displayed.";

 

At the first glance, you might think that the message, This will always displayed, will always be displayed. But in fact the code displays nothing because the else clause is not associated with the if (false); it is associated with if (true). By adding a little whitespace, you can see how the code really works

 

   if (false)

       if (true)

               cout << "This will never be displayed.";

   else

               cout << "This will always be displayed.";

 

 

I havent changed the meaning of the code (Remember whitespace is just a convenience for us humans), but i've made the meaning clearer. Because the outer if statement never executes its body, no message is ever displayed.

 

However i can solve the problem with a pair of curly braces.

 

   if (false)

{

       if (true)

               cout << "This will never be displayed.";

}

   else

               cout << "This will always be displayed.";

 

As a result, the inner if statement is set off in its own little world (called a scope) inside the block, and the else clause associates with if (false). Now the code will always display the message, This will always be displayed.

 

The guide is not 100% mine, some parts are from the book. I dont have the books name so i cant give credits ;]

 

Results of the main program;

After compiling a cmd window will pop up and it will ask you for the score.

 

ephtp2.jpg

 

If u write a score less than 500 then u will see this result:

 

2nv9fdx.jpg

 

If u write a score above than 1000 then u will see this result:

 

2nkv3g4.jpg

 

 

Posted

im thinking to start C++ but anyway if you want learn c++ you will be learn

for first steps in C++ this tutorial is good gratz ;)

Posted

well yes i remember that,and it's pretty good to learn the if else

btw a nice one would be to make the computer guess your number and print out his tries

you are gonna see how fast it work :P

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • I fixed it now my friends can join too, with what do you want help with? Also can you upload the interlude client of gx-ext for c4? just to have it because i deleted the rar i just have the folder
    • me ayudas a montar ese pack por que no entiendo tanto es para tener de prueba
    • GX-C4 pack, its ok...just used it.
    • This post originally appeared on MmoGah. Arena Breakout: Infinite is a hardcore tactical extraction shooter that demands precision, patience, and strategy. This guide will walk you through everything a beginner needs to know—from gear and combat to survival and extraction.     What Is Arena Breakout: Infinite? Arena Breakout: Infinite (ABI) is a free-to-play online extraction shooter developed by MoreFun Studios and released on Steam in September 2025. Unlike traditional battle royales, ABI focuses on risk vs. reward rather than being the last one standing. Players enter instanced maps called "raids," where they must scavenge loot, survive enemy encounters, and extract safely.   Core Gameplay Mechanics 1. Raids and Extraction Each raid features 4–6 teams (solo or squad) dropped into a map. The goal is to loot valuable items and extract through designated points. Extraction is not exclusive—multiple teams can leave the map alive. 2. PvPvE Combat You'll face both human players and AI enemies. AI can be unpredictable and deadly, especially in high-tier zones. 3. No Hand-Holding ABI offers no tutorials or guidance. You learn by dying—and surviving.   Gear and Loadouts 1. Choose Wisely Your gear determines your survivability. Armor, helmets, and medical supplies are essential. Weapons vary in recoil, damage, and handling. Start with low-cost rifles like the AKS-74U or MP5. 2. Insurance System You can insure gear to recover it if you die and it isn't looted. Use insurance for expensive items, but don't rely on it blindly. 3. Backpacks and Storage Larger backpacks allow more loot but make you a bigger target. Organize your inventory to quickly access meds and ammo during combat.   Tactical Tips for Beginners 1. Know What to Loot Prioritize high-value items like weapon parts, medical kits, and rare electronics. Learn loot hotspots on each map—warehouses, bunkers, and military zones often yield better gear. 2. Sound Is Everything Footsteps, gunfire, and reloads are loud. Use headphones and move cautiously. Crouch-walking and slow peeking reduce noise and improve stealth. 3. Map Knowledge Study maps offline or in low-risk raids. Learn extraction points, choke zones, and sniper nests. 4. Stamina Management Sprinting drains stamina, which affects aim and movement. Rest in safe zones and avoid overexertion during firefights.   Combat and Survival 1. Engage Smartly Don't chase kills—survival and extraction are the real goals. Use cover, lean mechanics, and suppressive fire to control fights. 2. Healing and Damage ABI features a detailed health system: limbs can be fractured, bleeding, or disabled. Carry splints, bandages, and painkillers. Know how to treat each condition. 3. Death Is a Lesson You will die—a lot. Use each death to learn positioning, gear value, and enemy behavior.   Progression and Economy 1. Free-to-Play Friendly ABI is generous with starter gear and daily rewards. You can earn the currency Arena Breakout: Infinite Koens through successful raids and selling loot. 2. Marketplace Trade gear with other players or sell to vendors. Prices fluctuate—learn market trends to maximize profit. 3. No Skill Trees Unlike similar games, ABI doesn't use operator skills. Progression is gear-based and tactical, not RPG-style.   Settings and Optimization 1. Graphics and Performance Lower shadows and post-processing for better visibility. Use high FPS settings for smoother combat. 2. Keybinds Customize controls for quick access to healing, leaning, and inventory. Practice muscle memory in offline raids. 3. Audio Settings Maximize footstep and gunfire volume. Reduce ambient noise to focus on threats.   Beginner Loadout Recommendation Slot Item Notes Primary Gun AKS-74U or MP5 Low recoil, easy to handle Secondary Pistol (optional) Backup for emergencies Armor Basic Vest Better than nothing Helmet Light Helmet Protects against headshots Backpack Medium Balance between space and size Meds Bandages, Splints Treat bleeding and fractures Ammo 2–3 extra mags Always reload before fights         Final Advice for New Players Start slow: Don't rush into high-tier zones. Learn the basics in low-risk areas. Play with friends: Squad play improves survival and makes learning easier. Watch and learn: Study streamers and guides to understand advanced tactics. Don't hoard: Use your gear. Hoarding leads to stagnation and fear of loss. Extract often: Surviving and extracting builds confidence and resources. Arena Breakout: Infinite is brutal, but deeply rewarding. With patience and practice, you'll evolve from a terrified scavenger to a confident operator. Every raid is a story—make yours one of survival and triumph.
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock