C/C++ Arena

Step 1 of 7

Hello, C++

Welcome to C++. Bjarne Stroustrup started it in 1979 as "C with Classes" and renamed it C++ in 1983, and almost everything you learned in C still works: variables, if, loops, functions, pointers, arrays and structs. What C++ adds are tools that make programs safer and shorter: classes that clean up after themselves, a huge standard library (strings, dynamic arrays, maps, algorithms), references, templates and more.

The first difference you'll notice is output. Instead of printf with format specifiers, C++ uses streams:

#include <iostream>

int main() {
    int kills = 25;
    double accuracy = 0.61;
    std::cout << "Kills: " << kills << "\n";
    std::cout << "Accuracy: " << accuracy << " (" << accuracy * 100 << "%)\n";
}
Kills: 25
Accuracy: 0.61 (61%)

How it works

You'll see std::endl in older code; it prints a newline and flushes the stream, which is slower. "\n" is usually what you want.

Your task

Print Rounds won: 13 using cout.

Challenge 2

Print the K/D as 25/12 by chaining the two variables and a "/" in one std::cout statement.

Challenge 3

Using the variables, print these three lines with std::cout. Compute the rounds played instead of typing 24:

Map: mirage
Rounds: 24
Score: 13-11

Next: Reading with cin