C++ question *program edited**

nick1985

Lifer
Dec 29, 2002
27,153
6
81

// This is weak, so feel free to steal it from me.


#include<iostream.h>
#include <cstdlib>
#include <time.h>

void roller (int* pH);

void main () {
int iAC;
int iThaco;
int iToHit;
char cYN;
int* pHit;
pHit = &iToHit;
cout<<"Input your character's modified THAC0:"<<endl;
cin>> iThaco;
cout<<"Now Input the monster's AC:"<<endl;
cin>> iAC;

iToHit = (iThaco - iAC);
cout<<"You Need a "<<iToHit<<" on a 1d20"<<endl<<endl;

cout<<"Do you wish to go onto the built in dice roller? y/n" <<endl;
cin >> cYN;

if ((cYN == 'y')||(cYN == 'Y'))
roller (pHit);
}

void roller (int* pH){
int iroll;
char cYN;
srand((unsigned)time(NULL));

do{
iroll = 1+ rand()%20 ;
if (iroll==20)
cout<< "Critical Hit! Roll Double Damage!"<<endl;
else if (iroll >= *pH)
cout<<"You HIT with a roll of " << iroll<<endl;
else if (iroll==1)
cout<<"Critical Miss! The DM will now punish you for sucking"<<endl;
else
cout<<"You MISS with a roll of "<<iroll<<endl;
cout<<"Do you wish to roll again? y/n"<<endl;
cin>> cYN;
}while ((cYN=='Y')||(cYN=='y'));
main();

}



does that make ANY sense? where are the errors?
 

Staples

Diamond Member
Oct 28, 2001
4,953
119
106
You probably can't call main from a function and

cout= *pH)
cout> cYN;


mean absolutely nothing.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
first of all, you are using <cstdlib> which means you are using the new header include convention, so everything in the std lib is in the "std" namespace. so you need a "using namespace std;" directive after the includes, unless you use a compiler that ignores this convention for some reason (some version of gcc did this in my experience) - this maybe the reason why you are gettting an error on srand((unsigned)time(NULL));

btw i would also use <iostream> and <ctime> for more correctness