I am trying to create a health damage meter for the text-based RPG I am working on. I want the HP to get to 0. However I keep getting an output like this:
opponents hp is now 70
will you attack?
1. yes
2.No
1
hp has been reduced to50
opponents hp is now 50
will you attack?
1. yes
2.No
1
hp has been reduced to50
opponents hp is now 50
will you attack?
1. yes
2.No
1
hp has been reduced to50
opponents hp is now 50
will you attack?
1. yes
2.No
1
hp has been reduced to50
opponents hp is now 50
will you attack?
1. yes
2.No
1
hp has been reduced to50
opponents hp is now 50
will you attack?
1. yes
2.No
Bearing in mind I haven't done anything with the dice until normal damage works perfectly, is there any way to do it without using multiple if
statements?
Here's the code:
#include <iostream>
#include <ctime>
#include <stdlib.h>
using namespace std;
void Dice();
void MainMenu();
//global variable
int result = 0;
//
void Dice() {
//dice functionality
srand( time( NULL ) );
int number = 100;
result = rand() % number + 1;
///
}
void MainMenu() {//variables
int HP = 70;
int HPtotal = 0;
int damage[7] = { 20, 20, 20, 20, 20, 20, 20 };
int choice;
//
HPtotal = HP;
// repeat infinetly
for ( int i = 0; i < 999; i++ ) {
//main menu
cout << "opponents hp is now " << HPtotal << endl;
cout << "will you attack?" << endl;
cout << "1. yes" << endl;
cout << "2.No" << endl;
cin >> choice;
//
//damage system
if ( choice == 1 ) {
HPtotal = HP - damage[i];
cout << "hp has been reduced to" << HPtotal << endl;
//while HPtotal is less than 70
//END OF SYSTEM
}
if ( choice == 2 ) {//if pressed 2
cout << "END OF PROGRAM BAKA" << endl;
system( "PAUSE" );
}//end if
}//end for
}
int main() {
MainMenu();
Dice();
}