Coding Newbie needing help with some minor issues:

Joined
Sep 21, 2022
Messages
170
Reaction score
24
There are 19 tab characters in the text file.

When indenting lines, use spaces or tabs. Using both ruins the shape if the viewing program and the original editor have different tab settings.

There are 31 {
There are 28 }

That suggests a problem.
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
Your code seems to be working fine, but there are some redundant and inconsistent lines of code, as well as possible improvements to make the code cleaner and more organized. Here's what you can do:

  1. Remove redundant variables like name and ability, as they don't seem to be used in the program.
  2. Replace sleep(3) with std::cout << std::endl to create line breaks between outputs.
  3. Replace multiple std::cout << "Now that you've gotten your ... done, let's move on to..." with one std::cout << "Moving on to...
  4. Instead of using if (level > 100) repeatedly, use while (level > 100) and put the input and message inside the loop.
Here's the updated code:

Code:
#include <iostream>

int main()
{
    double armor, weapon, level, defense, health, total_durability, total_damage, remaining, ability_level, base_power, ability_damage;
 
    std::cout << "Welcome To The STEVEN Stats Calculator\n"
              << "Here You Can Test Calculations Including Stats, Armory, Weaponry, and Special Abilities.\n"
              &#8203;`oaicite:{"index":0,"invalid_reason":"Malformed citation << \"What is the Armor Stat of the character?\\n\";\n    std::cin >>"}`&#8203; armor;
    std::cout &#8203;`oaicite:{"index":1,"invalid_reason":"Malformed citation << \"What is the Weapon Stat of the character?\\n\";\n    std::cin >>"}`&#8203; weapon;
    std::cout &#8203;`oaicite:{"index":2,"invalid_reason":"Malformed citation << \"What is the Level Stat of the character?\\n\";\n    while (level > 100) {\n        std::cin >>"}`&#8203; level;
        if (level > 100) {
            std::cout << "Please enter a level below 100\n";
        }
    }

    defense = 80 + armor;
    attack = 80 + weapon;
    health = (defense + level) / 2;
    speed = (defense * health) / (armor + level) * 2;
    std::cout << "Your Attack is " << attack << '\n'
              << "Your Defense is " << defense << '\n'
              << "Your Health is " << health << '\n'
              << "Your Speed is " << speed << '\n'
              << "Moving on to Durability\n"
              &#8203;`oaicite:{"index":3,"invalid_reason":"Malformed citation << \"What is the total durability?\\n\";\n    std::cin >>"}`&#8203; total_durability;
    std::cout &#8203;`oaicite:{"index":4,"invalid_reason":"Malformed citation << \"How much damage is dealt?\\n\";\n    std::cin >>"}`&#8203; total_damage;
    remaining = total_durability - total_damage;
    std::cout << "Your Remaining Durability is " << remaining << '\n'
              << "Moving on to Abilities\n"
              << "Available abilities: Final_Power, Fireblazer, Shadow_Sphere, Dark_And_Stormy_Night, Electropunch, Kneeslapper, Glare, Instrumental_Doom, Flower_Power, weneedtocook, Magic_Pulse, Heal_Spell\n"
              &#8203;`oaicite:{"index":5,"invalid_reason":"Malformed citation << \"Enter ability name: \\n\";\n    std::cin >>"}`&#8203; ability;
    if (ability == "Final_Power") {
        std::cout &#8203;`oaicite:{"index":6,"invalid_reason":"Malformed citation << \"What's The Ability Level?\\n\";\n        std::cin >>"}`&#8203; ability_level;
        while (ability_level > 10) {
            std
 
Joined
Jan 30, 2023
Messages
2
Reaction score
0
  1. The 'while (true)' loop in line 65 does not break and runs infinitely. This is because the condition inside the loop does not change and there is no 'break' statement that would allow the loop to end.
  2. The 'break' statement in line 77 is not inside an if statement, so it breaks out of the loop no matter what the value of 'ability_level' is.
  3. The same issue in point 2 also occurs in line 89.
It's also worth noting that there are a few stylistic issues in the code, such as using 'sleep(n)' instead of 'std::this_thread::sleep_for(std::chrono::seconds(n))' or using 'std::cin' instead of 'std::getline(std::cin, string_variable)'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top