So I've never worked with percentages in c++ and I was wondering how to incorporate into a program I'm making for a game so see what the chances are that an item will reach a certain level depending on the chance of success for each different level.
Here's what I have so far, all I need is how to do the percentages.
#include <iostream>
#include <cmath>
int main () {
int itemlevel = 0;
int requiredlevel = 0;
bool upgradesuccess = false;
bool upgradefailed = false;
bool itembroken = false;
double percentageofsuccess = 0;
cout >> "What Level is the item you want to upgrade?/n";
cin >> itemlevel;
cout >> "/nWhat Level do you want your item to be upgraded to?/n";
cin >> requiredlevel;
while (item != requiredlevel){
if (itemlevel == 0 || itemlevel == 1 || itemlevel == 2) {
itemlevel = itemlevel + 1; // 100% chance item will succeed
}
if (itemlevel == 3 && requiredlevel >= 4){
//80% chance item will succeed
if (upgradesuccess = true) item = item + 1;
else if (upgradefailed = true) item = item;
}
if (itemlevel == 4 && requiredlevel >= 5){
//60% chance item will succeed
if (upgradesuccess = true) item = item + 1;
else if (upgradefailed = true) item = item;
}
if (itemlevel == 5 && requiredlevel >= 6){
//%50 chance item will succeed
if (upgradesuccess = true) item = item + 1;
else if (upgradefailed = true) item = item;
}
if (itemlevel == 6 && requiredlevel >= 7){
//45% chance item will succeed 25% chance the item will be destroyed
if (upgradesuccess = true) item = item + 1;
else if (upgradefailed = true) item = item;
else if (itembroken = true) cout >> "The item has broken during upgrading./n";
}
if (itemlevel == 7 && requiredlevel >= 8){
//40% chance item will succeed 25% chance the item will be destroyed
if (upgradesuccess = true) item = item + 1;
else if (upgradefailed = true) item = item;
else if (itembroken = true) cout >> "The item has broken during upgrading./n";
}
if (itemlevel == 8 && requiredlevel >= 9){
//35% chance item will succeed 25% chance the item will be destroyed
if (upgradesuccess = true) item = item + 1;
else if (upgradefailed = true) item = item;
else if (itembroken = true) cout >> "The item has broken during upgrading./n";
}
if (itemlevel == 9 && requiredlevel >= 10){
//30% chance item will succeed 25% chance the item will be destroyed
if (upgradesuccess = true) item = item + 1;
else if (upgradefailed = true) item = item;
else if (itembroken = true) cout >> "The item has broken during upgrading./n";
}
if (itemlevel == 10 && requiredlevel >= 11){
//25% chance item will succeed 25% chance the item will be destroyed
if (upgradesuccess = true) item = item + 1;
else if (upgradefailed = true) item = item;
else if (itembroken = true) cout >> "The item has broken during upgrading./n";
}
if (itemlevel == 11 && requiredlevel == 12){
//20% chance item will succeed 25% chance the item will be destroyed
if (upgradesuccess = true) item = item + 1;
else if (upgradefailed = true) item = item;
else if (itembroken = true) cout >> "The item has broken during upgrading./n";
}
cout >> "There is a: " << percentageofsuccess << "Percent Chance your item will reach the desired level."
}
Cin.get();
return 0;
}