Question: how can I improve or make my code better #include #include int main ( ) { std :: string playername; std :: cout < <

how can I improve or make my code better
#include
#include
int main(){
std :: string playername;
std :: cout << "Enter your player name: ";
std :: getline(std :: cin, playername);
std :: cout << "Welcome "<< playername <<" let's get you started on your way.
";
int choice;
const int wizard =1, knight =2, rogue =3;
int magic =0, strength =0;
std :: cout << "Enter the number of the character you want (1-3):
";
std :: cout <<"1. Wizard {+8 magic, +2 strength}
";
std :: cout <<"2. Knight {+0 magic, +8 strength}
";
std :: cout <<"3. Rogue {+4 magic, +4 strength}
";
std :: cin >> choice;
if(choice == wizard){
std :: cout << "You have chosen the Wizard
";
magic =8;
strength =2;
}
else if(choice == knight){
std :: cout << "You have chosen the Knight
";
magic =0;
strength =8;
}
else if(choice == rogue){
std :: cout << "You have chosen the Rogue
";
magic =4;
strength =4;
}
else{
std :: cout << "Please enter a valid response
";
}
int item;
std :: cout << "Enter the number of what item you want (1-10)
";
std :: cout <<"1. Sword of the Morning, this sword is granted only to those that are worthy, (+8 strength)
";
std :: cout <<"2. Necklace of Wisdom, this necklace offers the user enhanced wisdom, (+8 magic)
";
std :: cout <<"3. Solarflare Staff, a staff that allows the user fire magic, (+6 magic and +2 strength)
";
std :: cout <<"4. Achilles bow, this bow is has accurate has they come, (+6 strength)
";
std :: cout <<"5. Jewel of frost, this jewel allows the user frost magic, (+6 magic)
";
std :: cout <<"6. Dagger of Sorrow, this blade yet small packs a mean punch, (+4 strength and +4 magic)
";
std :: cout <<"7. Crossbow, trusty crossbow can never go wrong, (+4 strength)
";
std :: cout <<"8. Spellkeeper Book, this gook grants the user enhanced magical powers, (+8 magic)
";
std :: cout <<"9. Magic Wand, can't go wrong with a simple wand, (+6 magic)
";
std :: cout <<"10. Lighning spear, a spear that allows the user to summon mystical powers, (+4 magic and +6 strength)
";
std :: cin >> item;
std :: string itemName;
switch(item){
case 1:
std :: cout << "You have chosen the Sword of the Morning
";
itemName = "Sword of the Morning";
strength +=8;
break;
case 2:
std :: cout << "You have chosen the Necklace of Wisdom
";
itemName = "Necklace of Wisdom";
magic +=8;
break;
case 3:
std :: cout << "You have chosen the Solarflare Staff
";
itemName = "Solarflare Staff";
magic +=6;
strength +=2;
break;
case 4:
std :: cout << "You have chosen the Achilles bow
";
itemName = "Achilles bow";
strength +=6;
break;
case 5:
std :: cout << "You have chosen the Jewel of Frost
";
itemName = "Jewel of Frost";
magic +=6;
break;
case 6:
std :: cout << "You have chosen the Dagger of Sorrow
";
itemName = "Dagger of Sorrow";
magic +=4;
strength +=4;
break;
case 7:
std :: cout << "You have chosen the crossbow
";
itemName = "Crossbow";
strength +=4;
break;
case 8:
std :: cout << "You have chosen the Spellkeeper Book
";
itemName = "Spellkeeper Book";
magic +=8;
break;
case 9:
std :: cout << "You have chosen the Magic Wand
";
itemName = "Magic Wand";
magic +=6;
break;
case 10:
std :: cout << "You have chosen the Lighning Spear
";
itemName = "Lightning Spear";
magic +=4;
strength +=6;
break;
default:
std :: cout << "Please enter a valid response
";
return 1;
}
std :: cout << "Player stats:
";
std :: cout << "Magic: "<< magic << std :: endl;
std :: cout << "Strength: "<< strength << std :: endl;
std :: cout << "Item: "<< itemName << std :: endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!