Please Help
#1 _*D34DM347_*
Posted 18 February 2005 - 11:29 AM
#include <iostream.h>
#include <conio.h>
#include <time.h>
void main( )
{
struct tm *local;
time_t t;
t = time(NULL);
local = localtime(&t);
int hp1, hp2, hp3, hpmain, answer;
hp1 = 100;
hp2 = 100;
hp3 = 100;
hpmain = 250;
cout << "Do you attack skeleton 1, 2, or 3?" << endl;
cin >> answer;
switch (answer) {
case '1': cout << "You attack monster 1." << endl;
cout << local->tm_sec << " damage was dealt to monster 1." << endl;
hp1 = hp1 - local->tm_sec;
cout << hp1 << " hit points left." << endl;
if (local->tm_sec = 0);
cout << "You missed!" << endl;
break;
case '2': cout << "You attack monster 2." << endl;
cout << local->tm_sec << " damage was dealt to monster 2." << endl;
hp2 = hp2 - local->tm_sec;
cout << hp2 << " hit points left." << endl;
if (local->tm_sec = 0);
cout << "You missed!" << endl;
break;
case '3': cout << "You attack monster 3." << endl;
cout << local->tm_sec << " damage was dealt to monster 3." << endl;
hp3 = hp3 - local->tm_sec;
cout << hp3 << " hit points left." << endl;
if (local->tm_sec = 0);
cout << "You missed!" << endl;
break;
}
}
#2
Posted 19 February 2005 - 11:35 PM
#3 _*D34DM347_*
Posted 21 February 2005 - 11:26 AM
#4 _*D34DM347_*
Posted 28 February 2005 - 11:33 AM
#5
Posted 28 February 2005 - 01:32 PM
I took the time to edit the code you posted above and it compiles with some warnings but no errors and runs fine. You should really check into some of the warnings and try fixing them.Well, it doesn't matter that no one helped me, because I fixed it myself.
I would like to show you a few improvements I made to your code.
I noticed you had a variables hp1, hp2, hp3 all equal 100. You had it like this,
int hp1, hp2, hp3, hpmain, answer; hp1 = 100; hp2 = 100; hp3 = 100;
If they are all going to be the same value just set them to the value, "100" when you defined them like so,
int hp1, hp2, hp3, hpmain, answer = 100;
I also saw in your switch statement that you used hp1, hp2, hp3. Why not just use one variable for this? hp1 for example. Unless you plan on putting this in a while loop you should just use one variable for the whole process.
#include <iostream.h> #include <conio.h> #include <time.h> using namespace std; int main() { struct tm *local; time_t t; t = time(NULL); local = localtime(&t); int hp1, hp2, hp3, hpmain, answer; hp1, hp2, hp3 = 100; hpmain = 250; cout << "Do you attack skeleton 1, 2, or 3?" << endl; cin >> answer; switch(answer) { case 1: cout << "You attack skeleton 1." << endl; cout << local->tm_sec << " Damage was dealt to monster 1." << endl; hp1 = hp1 - local->tm_sec; if(local->tm_sec=0) { cout << "You missed!" << endl; } break; case 2: cout << "You attack monster 2." << endl; hp2= hp2 - local->tm_sec; cout << hp2 << " hit points left." << endl; if(local->tm_sec = 0) { cout << "You missed!" << endl; } break; case 3: cout << "You attack monster 3." << endl; hp3 = hp3 - local->tm_sec; cout << hp3 << " hit points left." << endl; if(local->tm_sec =0 ){ cout << "You missed!" << endl; } break; } }I
#6 _*D34DM347_*
Posted 09 March 2005 - 11:34 AM
#7
Posted 10 March 2005 - 11:40 AM
i think this is gonna end up in a banI'm increasing my post count!
#8 _*D34DM347_*
Posted 10 March 2005 - 11:42 AM
#9 _*D34DM347_*
Posted 10 March 2005 - 11:43 AM
#10 _*D34DM347_*
Posted 10 March 2005 - 11:45 AM
#11
Posted 16 March 2005 - 10:59 PM
It sure did!i think this is gonna end up in a banI'm increasing my post count!
Faken
#12
Posted 17 July 2005 - 07:30 AM
Well, it doesn't matter that no one helped me, because I fixed it myself.
Could you post your final code too? I'm curious how you did it..!
#13
Posted 17 July 2005 - 10:23 AM
No, he can't, he's been bannedWell, it doesn't matter that no one helped me, because I fixed it myself.
Could you post your final code too? I'm curious how you did it..!
#14
Posted 17 July 2005 - 11:00 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users