Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 10th, 2007, 10:13 PM   #11
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You also have a rather obvious problem here:
int main(){
 while (1 == 1) {
           string name;
           int ready;
           int option;
           int money;
           int enemydmg;
           int yourdmg;
          srand ( time(NULL) );
          enemydmg = rand() % 10 + 1;
          yourdmg = rand() % 10 + 1;
          
          
//Opening   
cout << "Hello there! What's your name?: \n";
getline (cin, name);
cout << "Welcome,";
cout << name;
cout << " , to Mage Wars! We are in a world of need, and we are hoping a true"; 
cout << "hero like you would help us! Please! Destroy the evil mages! \n\n";
cout << "Are you ready? 1: Yes 2: No \n";
cin >> ready;
          
   	} else if(ready == 2){
    cout << "Come back when you are ready!";
    
    	} else {
A preceding "if" would be nice. Additionally, your "while" at the very top can be somewhat problematic, although it can work. Perhaps you should have a read regarding scope. "while (1 == 1)" can also be replaced by "while (true)" or "for (;;;)", although if won't really reduce your code size. The latter will be more efficient (marginally) if no optimization is taking place.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 10th, 2007, 10:33 PM   #12
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Thanks guys, all is going well, but I have a question...
//attack one

if (enemyhealth <= 0) 
{
cout << "You have slain the vile enemy! You now gain 10 gold!";
	money = money + 10;
}
else if (yourhealth > 0)
{
	cout << "Enemy attacks you with  " << enemydmg << "  damage! You attack back: \n" ;
	yourhealth = yourhealth - enemydmg;
	cout << "You deal  " << yourdmg << "   damage! \n";
	enemyhealth = enemyhealth - yourdmg;
	cout << "Your health is " << yourhealth << ". The enemy's health is" << enemyhealth << ". \n";
}
else
{

cout << "You have died in the mists of battle! I am sorry! The enemy steals 10 gold!";
	money = money - 10;

}
//end attack one
You see, what I did was copy and paste that 10-15 times (I know it sounds crude... blah) and it would say You Killed Enemy, you get ten gold! Or it would say You die and lose 10 gold... but what my program did was just keep repeating over and over that "I killed the enemy and I got 10 gold" until all the copied/pasted code was full-filled. I need some way to pause and go back to the main menu (while (1 == 1))...
Thanks!
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Aug 10th, 2007, 10:51 PM   #13
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You also need to pay attention to your responses, and to pursue a logical design. I can copy and paste the works of old masters twelve jillion times, but that does not make me an artist. Shit, it doesn't make me successful, either, unless I really luck out. Now, if you'll excuse me, I'll go play the lottery, where the odds against are only lebenty-four quadrillion to one.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 10th, 2007, 11:03 PM   #14
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
I've been paying attention...
And I've fixed what is told to be fixed.
Like I said, no errors, no bugs.. just this problem.
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Aug 10th, 2007, 11:26 PM   #15
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
Why would you copy and paste ten times?

Why not use:

while ( yourhealth > 0 && enemyhealth > 0 )
{
     ...
}
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Aug 10th, 2007, 11:32 PM   #16
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
Quote:
Originally Posted by Prm753 View Post
Why would you copy and paste ten times?

Why not use:

while ( yourhealth > 0 && enemyhealth > 0 )
{
     ...
}
Well I'm a newbie, and I don't really get what you said.
I mean yeah, that would help dramatacly, I'm just trying to get this thing to work... I need something that returns you back to the main menu or wherever the "while (1 == 1) {" is.
Arnack
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Old Aug 11th, 2007, 12:40 AM   #17
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 855
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Perhaps the continue keyword is what you are looking for:
while (1) {
    ...
    if (time_to_start_over)
        continue; // skip to the next iteration of the while loop
    ...
}
titaniumdecoy is offline   Reply With Quote
Old Aug 11th, 2007, 12:42 AM   #18
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
while ( 1 == 1 )

is equivelent to

while ( true )

or, in C,
while ( 1 )
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Aug 11th, 2007, 12:50 AM   #19
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Okay, here's the deal. You need to design your program. That's language independent.

You need to decide, logically, what it's going to do. You need to describe that in high-level (abstract) terms. You then need to break it down. Divide and conquer. The breakdown needs to be in abstract terms. Then you need to take those human-oriented expressions and implement them in your language of choice.

Copying someone else's code, even if you luck out and get it to "work", is not the same thing as being a programmer. A Xerox machine can do that, but not many people would depend on a Xerox machine to guarantee their bottom line.

Everyone I ever met was a newbie when they started. Decide what you're going to do. Design it. The language is just a tool for ultimate execution. When you pick the tool, try to learn the basics ('else' doesn't fly without an 'if'). When you have problems, post here. Help is readily forthcoming for those who are actually trying.

(Glad you pointed that out, Jesse, my post #11 was probably not read in its entirety.)
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 11th, 2007, 12:50 AM   #20
Arnack
Programmer
 
Join Date: Jul 2005
Posts: 66
Rep Power: 4 Arnack is on a distinguished road
#include <stdio.h>
#include <stdlib.h>
#include <time.h> 
#include <iostream>
//"Mage Wars" copyright Crimson Games 2007. All rights reserved.
//Created by Arnack, distributing this source is permited, as long
//as ownership is shown.
using namespace std;

int main(){
    
           string name;
           int ready;
           int option;
           int money;
           int enemydmg;
           int yourdmg;
           int weapon;
           int yourhealth;
           yourhealth=50;
           int enemyhealth;
           enemyhealth=50;
          srand ( time(NULL) );
          enemydmg = rand() % 10 + 1;
          yourdmg = rand() % 10 + 1;
          money = 10;
          weapon = 1;
          
          
          
          
//Opening   
cout << "\n \n Hello there! What's your name?: \n";
getline (cin, name);
cout << "Welcome,";
cout << name;
cout << "  , to Mage Wars! We are in a world of need, and we are hoping a true"; 
cout << "hero like you would help us! Please! Destroy the evil mages! \n\n";
cout << "Are you ready? 1: Yes 2: No \n";
cin >> ready;
           
          while ( true ) {
          
   if (ready == 1){
       
//Main Game Starts Here
	cout << "\n What would you like to do? \n";
	cout << "1) Kill some evil mages! \n";
	cout << "2) Buy some stuff! \n";
	cout << "3) Check my status! \n";
	cin >> option;
	
if (option == 1){
//attack sequence
 while (5 == 5) {
//attack one

if      (enemyhealth <= 0) 
{
cout << "You have slain the vile enemy! You now gain 10 gold!\n\n";
	money = money + 10;
	break;
}
else if (yourhealth > 0)
{
	cout << "Enemy attacks you with  " << enemydmg << "  damage! You attack back: \n" ;
	yourhealth = yourhealth - enemydmg;
	cout << "You deal  " << yourdmg << "   damage! \n";
	enemyhealth = enemyhealth - yourdmg;
	cout << "Your health is " << yourhealth << ". The enemy's health is " << enemyhealth << ". \n";
}
else if    (yourhealth <= 0)
{

cout << "You have died in the mists of battle! I am sorry! The enemy steals 10 gold! \n\n";
	money = money - 10;
break;

}
//end attack one

}

	} else if(option == 2){
int option2;
		cout << "So you would like to buy some weapons? \n";
		cout << "1) Level 3 Weapon: Flaming Sceptor. 20 gold. \n";
		cout << "2) Level 5 Weapon: Crystol Wand. 40 gold. \n";
		cout << "3) Level  10 Weapon: Stave of Mages. 100 gold. \n";
        cin >> option2;
if (option2 == 1){
         
money = money - 20;
weapon = weapon + 2;
yourdmg = rand() % 15 + 1;

	cout << "You have purchased the item. You now do 0-15 damage.\n" ;

}

	} else if(option == 3){

		cout << "\n You have " << money <<  " gold. Your weapon level is " << weapon << ". Have a nice day.";
	} else {

		cout << "Wrong reply!";

	}
	//END What would you like to do
	

system("PAUSE");
}
}
}
It's sloppy yes... but there are 3 problems.
1) When I engage in a battle all it only produces a random number ONCE and uses it the whole battle. So I only attack for 5 dmg or whatever, it's suppose to be random each time.
2) When I complete a battle, it brings me back to the 3 options. If I want to battle again, it won' let me. It just won't do anything.
3) I am not done with the weapon selection, but from the test I made... I can't seem to do a good job with the money and buying weapons. Someone with no money could buy any weapon they want, and I tried putting up else ifs "You have no money!" but it wouldn't work.
THANKS!
Arnack
BTW: I've tried what was said on this forum, I just can't get to it -.-
__________________
Ack Network
*UNDER CONSTRUCTION*
Now hiring staff of all sorts.
Arnack is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A simple programming question punter C# 8 Jan 5th, 2006 4:04 PM
A simple question Master C++ 9 Dec 24th, 2005 2:20 PM
Question about multidimensional arrays of strings aznluvsmc C 8 Oct 15th, 2005 10:20 PM
Simple c# question nez C# 8 Jul 1st, 2005 6:29 PM
Simple (stupid cause I don't know it) basic question massive-war C++ 17 Apr 11th, 2005 11:03 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:24 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC