Define auto type variable and do math calculation on them - C++ Data Type

C++ examples for Data Type:auto

Description

Define auto type variable and do math calculation on them

Demo Code

#include <iostream> 
 
int main() // www.ja  v a  2s  .com
{ 
    // define character values 
    auto strength = 8; 
    auto accuracy = 4.5; 
    auto dexterity = 2.0; 
 
    // define constants 
    const auto MAXIMUM = 50; 
 
    // calculate character combat stats 
    auto attack = strength * (accuracy / MAXIMUM); 
    auto damage = strength * (dexterity / MAXIMUM); 
 
    std::cout << "\nAttack rating: " << attack << "\n"; 
    std::cout << "Damage rating: " << damage << "\n"; 
}

Result


Related Tutorials