I am a C++ beginner and I am stuck. I can't get the random number generators to run properly, specifically the random number generators are all coming up with 1 . The point system is not running properly either, I'm sure it has something to do with my do-while loop. Any insight would be appreciated.

#include<iostream>
#include<ctime>
#include<fstream>

using namespace std;

int main()
{
  // Declare and initialize variables
  
  string fileUname = " ";  
  string uname = " ";
  int fileScore = 0;  
  int charaChoice = 0;
  int mainChoice = 0;
  int weapChoice = 0;
  int score = 0;
  int harry = 100;
  int yoda = 200;
  int gandolf = 300;
  int wand = 0;
  int lSaber = 0;
  int magic = 0;
  int weapRand = 0, i=0;
  int magicRand = 0, y=0;

  // Introduction

  cout << "WELCOME TO TARGET PRACTICE!!!\n\n\n";

  // Prompt user for name
    cout << "Enter your name: ";
    getline(cin,uname);

  // Display main menu around a Do while loop
 
    do{
  cout<<"Please choose from the following menu\n";
  cout<<"\t1) See rules\n";
  cout<<"\t2) Play game\n";
  cout<<"\t3) Exit\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>mainChoice;
  
  switch(mainChoice)
    {
    case 1:
      cout<<"\tChoose 2 to start playing the game then pick a character and weapon\n\n\n";
      break;
    case 2:
      cout<<"\tGet ready for your adventure!!!\n";
       break;
    case 3:
      cout<<"\tThanks for playing!!!Bye\n";
return 0;
     break;
    default:
    cout<<"Invalid choice please choose from the menu.\n";
    }    
  }
  while(mainChoice!=2);
 

  // Display character menu

  cout<<"Please choose from the following species\n";
  cout<<"\t1) Harry Potter\n";
  cout<<"\t2) Yoda\n";
  cout<<"\t3) Gandolf\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>charaChoice;

  //if (charaChoice = 1){
  //  charaChoice = harry;
  //}
  //else if (charaChoice = 2){
  //  charaChoice = yoda;
  //}
  //else if (charaChoice = 3){
  //  charaChoice = gandolf;
  //}
  switch(charaChoice){
    case 1:
    charaChoice = harry;
   break;
 case 2:
   charaChoice = yoda;
   break;
 case 3:
   charaChoice = gandolf;
   break;
 default:
   cout<< "Invalid choice choose again: ";
  }
  cout << charaChoice<<endl;

  // Display weapon menu
  do{
cout<<"Please choose from the following species\n";
  cout<<"\t1) Wand\n";
  cout<<"\t2) Light Saber\n";
  cout<<"\t3) Magic\n";
  cout<<"\t4) Try again\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>weapChoice;

  // if statement : if the user picks Flamethrower or Bow and arrow
  // randomly generate number from 1-4 for practice session
  if (weapChoice = 1){
    weapChoice = wand;
 srand(time(NULL)); //seed random number generator

  //generate 4 numbers
 for(i=1; i<=4; i++){
    
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
 }
      if (weapRand = 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }
      else if (weapRand = 2){
	cout<< "You hit Target B, 200 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (weapRand = 3){
	cout<< "You hit Target C, 300 points"<<endl;
      	charaChoice = charaChoice + 300;
      }
      else
      	cout<<"You missed the targets"<<endl;
      cout<<weapRand<<endl;
    
    

  }
  if (weapChoice = 2){
    weapChoice = lSaber;
srand(time(NULL)); //seed random number generator

  //generate 4 numbers
  
    {
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
if (weapRand = 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }
      else if (weapRand = 2){
	cout<< "You hit Target B, 200 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (weapRand = 3){
	cout<< "You hit Target C, 300 points"<<endl;
      	charaChoice = charaChoice + 300;
      }
      else
      	cout<<"You missed the targets"<<endl;
      cout<<weapRand<<endl;

    }



  }
  // if the user chooses magic user will randomly generate # number 
  // between 1-2 : if 1 increment 200 points if 2 decrement 100 points
  if (weapChoice = 3){
srand(time(NULL)); //seed random number generator

  //generate 2 numbers
  
  }
      magicRand = rand()%2 + 1; //generate a random number from 1 to 2
if (magicRand = 1){
	cout<< "Your potion worked, 200 points!!"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (magicRand = 2){
	cout<< "Your potion didn't work, minus 100 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
           
      
      cout<<magicRand<<endl;
  
    weapChoice = magic;
  }
  while(weapChoice!=4);

  cout << charaChoice<<endl;
  

  

  

  // if score reaches below 1 or after 10 tries end game

  // (outside of program) create text file "highscore.txt" containing first name and value 0
  // read in highscore.txt 
  // if score is greater than value in file replace with users name and score else do not change the file
  ifstream infile;
  infile.open("highscore.txt", ios::in);
  infile>>fileUname>>fileScore;
  infile.close();
  ofstream outfile;
  if(charaChoice > fileScore)
    //ofstream outfile;
  outfile.open("highscore.txt", ios::out);
  outfile<<uname<<" "<<charaChoice<<endl;
  outfile.close();


  
 
  return 0;
}
//generate 4 numbers
 for(i=1; i<=4; i++){
    
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
 }
      if (weapRand = 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }

Two problems. One, in your for-loop, you are creating a random number four times, but you are overwriting it three times before doing anything with it, so you are effectively producing only one random number.

Second problem. You are confusing = and ==. A very common mistake. In line 6 you are ASSIGNING weapRand to equal 1, not TESTING whether it IS equal to 1. Thus regardless of what random number was generated, it is overwritten in this line to equal 1. Change the = in this line (and in your other if statements) to == if you want to COMPARE the weapRand variable to a value.

ok, thank you, I fixed that but now I can't get out of the weapons do while loop to read and write the file and end the game, once I have that I think I'll be set to tweak it as neccesary and mess around with the scoring system.

[code=cplusplus]
#include<iostream>
#include<ctime>
#include<fstream>

using namespace std;

int main()
{
  // Declare and initialize variables
  
  string fileUname = " ";  
  string uname = " ";
  int fileScore = 0;  
  int charaChoice = 0;
  int mainChoice = 0;
  int weapChoice = 0;
  int score = 0;
  int harry = 100;
  int yoda = 200;
  int gandolf = 300;
  int wand = 0;
  int lSaber = 0;
  int magic = 0;
  int weapRand = 0, i=0;
  int magicRand = 0, y=0;

  // Introduction
  cout<< "****************************\n";
  cout<< "*********BE A HERO**********\n";
  cout<< "****************************\n\n\n\n";

  // Prompt user for name
    cout << "Enter your name: ";
    getline(cin,uname);

  // Display main menu around a Do while loop
 
    do{
  cout<<"Please choose from the following menu\n";
  cout<<"\t1) See rules\n";
  cout<<"\t2) Play game\n";
  cout<<"\t3) Exit\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>mainChoice;
  
  switch(mainChoice)
    {
    case 1:
      cout<<"\tChoose 2 to start playing the game then pick a character and weapon\n\n\n";
      break;
    case 2:
      cout<<"\tGet ready for your adventure!!!\n";
       break;
    case 3:
      cout<<"\tThanks for playing!!!Bye\n";
return 0;
     break;
    default:
    cout<<"Invalid choice please choose from the menu.\n";
    }    
  }
  while(mainChoice!=2);
 

  // Display character menu

  cout<<"Please choose from one of the following heroes\n";
  cout<<"\t1) Harry Potter\n";
  cout<<"\t2) Yoda\n";
  cout<<"\t3) Gandolf\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>charaChoice;

  switch(charaChoice){
    case 1:
    charaChoice = harry;
    cout<<"Expelliarmus!!!\n";
   break;
 case 2:
   charaChoice = yoda;
   cout<<"Do or do not! There is no try!\n"; 
   break;
 case 3:
   charaChoice = gandolf;
   cout<<"YOU SHALL NOT PASS!!!!!\n";
   break;
 default:
   cout<< "Invalid choice choose again: ";
  }
  cout << charaChoice<<endl;

  // Display weapon menu
  do{
cout<<"Please choose one from the following weapons\n";
  cout<<"\t1) Wand\n";
  cout<<"\t2) Light Saber\n";
  cout<<"\t3) Magic\n";
  cout<<"\t4) Finish\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>weapChoice;

  // if statement : if the user picks Flamethrower or Bow and arrow
  // randomly generate number from 1-4 for practice session
  if (weapChoice == 1){
    weapChoice = wand;
 srand(time(NULL)); //seed random number generator

  //generate 4 numbers
 // for(i=1; i<=4; i++){
    
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
      // }
      if (weapRand == 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }
      else if (weapRand == 2){
	cout<< "You hit Target B, 200 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (weapRand == 3){
	cout<< "You hit Target C, 300 points"<<endl;
      	charaChoice = charaChoice + 300;
      }
      else
      	cout<<"You missed the targets"<<endl;
      cout<<weapRand<<endl;
    
    

  }
  if (weapChoice == 2){
    weapChoice = lSaber;
srand(time(NULL)); //seed random number generator

  //generate 4 numbers
  
    {
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
if (weapRand == 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }
      else if (weapRand == 2){
	cout<< "You hit Target B, 200 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (weapRand == 3){
	cout<< "You hit Target C, 300 points"<<endl;
      	charaChoice = charaChoice + 300;
      }
      else
      	cout<<"You missed the targets"<<endl;
      cout<<weapRand<<endl;

    }



  }
  // if the user chooses magic user will randomly generate # number 
  // between 1-2 : if 1 increment 200 points if 2 decrement 100 points
  if (weapChoice == 3){
srand(time(NULL)); //seed random number generator

  //generate 2 numbers
  
  }
      magicRand = rand()%2 + 1; //generate a random number from 1 to 2
if (magicRand == 1){
	cout<< "Your magic worked, 200 points!!"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (magicRand == 2){
	cout<< "Your magic didn't work, minus 100 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
           
      
      cout<<magicRand<<endl;
  
    weapChoice = magic;
  }
  while(weapChoice!=4);

  cout << charaChoice<<endl;
   

  // if score reaches below 1 or after 10 tries end game

  // (outside of program) create text file "highscore.txt" containing first name and value 0
  // read in highscore.txt 
  // if score is greater than value in file replace with users name and score else do not change the file
  ifstream infile;
  infile.open("highscore.txt", ios::in);
  infile>>fileUname>>fileScore;
  infile.close();
  ofstream outfile;
  if(charaChoice > fileScore)

  outfile.open("highscore.txt", ios::out);
  outfile<<uname<<" "<<charaChoice<<endl;
  outfile.close();


  
 
  return 0;
}
//generate 4 numbers
 for(i=1; i<=4; i++){
    
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
 }
      if (weapRand = 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }

Two problems. One, in your for-loop, you are creating a random number four times, but you are overwriting it three times before doing anything with it, so you are effectively producing only one random number.

Second problem. You are confusing = and ==. A very common mistake. In line 6 you are ASSIGNING weapRand to equal 1, not TESTING whether it IS equal to 1. Thus regardless of what random number was generated, it is overwritten in this line to equal 1. Change the = in this line (and in your other if statements) to == if you want to COMPARE the weapRand variable to a value.

Look at lines 23, 182, and 184. In line 23, you assign magic to equal 0. In line 182 you declare weapChoice to equal magic. I see nowhere in your program where magic ever changes its value, so magic = 0 for the entire program, so line 182 is effectively this:

weapChoice = 0;

Line 184 compares weapChoice to 4. If weapChoice != 4, you'll never get past line 184. You assigned weapChoice to 0 in line 182, so effectively line 184 is this:

while(0 != 4)

This condition is always true, so you'll never get out of the do-while loop and thus you'll never get to the code where you store the high score.

So the question is, Do you intend for lines 169 through 182 to execute when the user enters 4 for weapChoice? Currently that is the way you have it. Your code for weapChoice == 3 is only from lines 163 to 168. Lines 169 - 182 are always executed for any weapChoice value. The comment says that you are generating random numbers in the weapChoice == 3 code block, but you are not. You are generating random numbers AFTER that code block ends on line 168. Is that intentional?

wow, duh I fixed that, stupid mistake with the weapChoice = magic. Now it seems to be working right, Thank You. I love Daniweb, what a resource for the coding illiterate!!

One more small problem
in the third menu if I choose magic it's fine, but if I choose either of the other two weapons it gives me the random number for it but ALSO gives me the same number 2 for the magic. Why does it loop in the magic code block?

[code=cplusplus]
#include<iostream>
#include<ctime>
#include<fstream>

using namespace std;

int main()
{
  // Declare and initialize variables
  
  string fileUname = " ";  
  string uname = " ";
  int fileScore = 0;  
  int charaChoice = 0;
  int mainChoice = 0;
  int weapChoice = 0;
  int score = 0;
  int harry = 100;
  int yoda = 200;
  int gandolf = 300;
  int wand = 0;
  int lSaber = 0;
  int magic;
  int weapRand = 0, i=0;
  int magicRand = 0, y=0;

  // Introduction
  cout<< "****************************\n";
  cout<< "*********BE A HERO**********\n";
  cout<< "****************************\n\n\n\n";

  // Prompt user for name
    cout << "Enter your name: ";
    getline(cin,uname);

  // Display main menu around a Do while loop
 
    do{
  cout<<"Please choose from the following menu\n";
  cout<<"\t1) See rules\n";
  cout<<"\t2) Play game\n";
  cout<<"\t3) Exit\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>mainChoice;
  
  switch(mainChoice)
    {
    case 1:
      cout<<"\tChoose 2 to start playing the game then pick a character and weapon\n\n\n";
      break;
    case 2:
      cout<<"\tGet ready for your adventure!!!\n";
       break;
    case 3:
      cout<<"\tThanks for playing!!!Bye\n";
return 0;
     break;
    default:
    cout<<"Invalid choice please choose from the menu.\n";
    }    
  }
  while(mainChoice!=2);
 

  // Display character menu

  cout<<"Please choose from one of the following heroes\n";
  cout<<"\t1) Harry Potter\n";
  cout<<"\t2) Yoda\n";
  cout<<"\t3) Gandolf\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>charaChoice;

  switch(charaChoice){
    case 1:
    charaChoice = harry;
    cout<<"Expelliarmus!!!\n";
   break;
 case 2:
   charaChoice = yoda;
   cout<<"Do or do not! There is no try!\n"; 
   break;
 case 3:
   charaChoice = gandolf;
   cout<<"YOU SHALL NOT PASS!!!!!\n";
   break;
 default:
   cout<< "Invalid choice choose again: ";
  }
  cout << charaChoice<<endl;

  // Display weapon menu
  do{
cout<<"Please choose one from the following weapons\n";
  cout<<"\t1) Wand\n";
  cout<<"\t2) Light Saber\n";
  cout<<"\t3) Magic\n";
  cout<<"\t4) Finish\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>weapChoice;

  // if statement : if the user picks Flamethrower or Bow and arrow
  // randomly generate number from 1-4 for practice session
  if (weapChoice == 1){
    weapChoice = wand;
 srand(time(NULL)); //seed random number generator

  //generate 4 numbers
 // for(i=1; i<=4; i++){
    
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
      // }
      if (weapRand == 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }
      else if (weapRand == 2){
	cout<< "You hit Target B, 200 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (weapRand == 3){
	cout<< "You hit Target C, 300 points"<<endl;
      	charaChoice = charaChoice + 300;
      }
      else
      	cout<<"You missed the targets"<<endl;
      cout<<weapRand<<endl;
    
    

  }
  if (weapChoice == 2){
    weapChoice = lSaber;
srand(time(NULL)); //seed random number generator

  //generate 4 numbers
  
    {
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
if (weapRand == 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }
      else if (weapRand == 2){
	cout<< "You hit Target B, 200 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (weapRand == 3){
	cout<< "You hit Target C, 300 points"<<endl;
      	charaChoice = charaChoice + 300;
      }
      else
      	cout<<"You missed the targets"<<endl;
      cout<<weapRand<<endl;

    }



  }
  // if the user chooses magic user will randomly generate #  
  // between 1-2 : if 1 increment 200 points if 2 decrement 100 points
  if (weapChoice == 3){
srand(time(NULL)); //seed random number generator
magicRand = rand()%2 + 1;
  //generate 2 numbers
  
  }
  //  magicRand = rand()%2 + 1; //generate a random number from 1 to 2
if (magicRand == 1){
	cout<< "Your magic worked, 200 points!!"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (magicRand == 2){
	cout<< "Your magic didn't work, minus 100 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
           
      
      cout<<magicRand<<endl;
  
      //weapChoice = magic;
  }
  while(weapChoice != 4);

  cout << charaChoice<<endl;
   

  // if score reaches below 1 or after 10 tries end game

  // (outside of program) create text file "highscore.txt" containing first name and value 0
  // read in highscore.txt 
  // if score is greater than value in file replace with users name and score else do not change the file
  ifstream infile;
  infile.open("highscore.txt", ios::in);
  infile>>fileUname>>fileScore;
  infile.close();
  ofstream outfile;
  if(charaChoice > fileScore)

  outfile.open("highscore.txt", ios::out);
  outfile<<uname<<" "<<charaChoice<<endl;
  outfile.close();


  
 
  return 0;
}

Look at lines 23, 182, and 184. In line 23, you assign magic to equal 0. In line 182 you declare weapChoice to equal magic. I see nowhere in your program where magic ever changes its value, so magic = 0 for the entire program, so line 182 is effectively this:

weapChoice = 0;

Line 184 compares weapChoice to 4. If weapChoice != 4, you'll never get past line 184. You assigned weapChoice to 0 in line 182, so effectively line 184 is this:

while(0 != 4)

This condition is always true, so you'll never get out of the do-while loop and thus you'll never get to the code where you store the high score.

So the question is, Do you intend for lines 169 through 182 to execute when the user enters 4 for weapChoice? Currently that is the way you have it. Your code for weapChoice == 3 is only from lines 163 to 168. Lines 169 - 182 are always executed for any weapChoice value. The comment says that you are generating random numbers in the weapChoice == 3 code block, but you are not. You are generating random numbers AFTER that code block ends on line 168. Is that intentional?


One more small problem
in the third menu if I choose magic it's fine, but if I choose either of the other two weapons it gives me the random number for it but ALSO gives me the same number 2 for the magic. Why does it loop in the magic code block?

Your program doesn't execute the magic code block if magic is not chosen. This is the magic code block:

if (weapChoice == 3){
srand(time(NULL)); //seed random number generator
magicRand = rand()%2 + 1;
  //generate 2 numbers
  }

This magic code block assigns a value of 1 or 2 to the variable magicRand. The code below executes for ALL choices of weapons, not just magic:

//  magicRand = rand()%2 + 1; //generate a random number from 1 to 2
if (magicRand == 1){
	cout<< "Your magic worked, 200 points!!"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (magicRand == 2){
	cout<< "Your magic didn't work, minus 100 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
           
      
      cout<<magicRand<<endl;

If you do not want this code to execute when the user enters 1, 2, or 4, you need to change your brackets so that the code above is inside the code block that only executes when weapChoice == 3.

Let's look at your entire do-while loop below.

// Display weapon menu
  do{
cout<<"Please choose one from the following weapons\n";
  cout<<"\t1) Wand\n";
  cout<<"\t2) Light Saber\n";
  cout<<"\t3) Magic\n";
  cout<<"\t4) Finish\n";
  cout<<"Enter choice here "<<uname<<": ";
  cin>>weapChoice;

  // if statement : if the user picks Flamethrower or Bow and arrow
  // randomly generate number from 1-4 for practice session
  if (weapChoice == 1){
    weapChoice = wand;
 srand(time(NULL)); //seed random number generator

  //generate 4 numbers
 // for(i=1; i<=4; i++){
    
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
      // }
      if (weapRand == 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }
      else if (weapRand == 2){
	cout<< "You hit Target B, 200 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (weapRand == 3){
	cout<< "You hit Target C, 300 points"<<endl;
      	charaChoice = charaChoice + 300;
      }
      else
      	cout<<"You missed the targets"<<endl;
      cout<<weapRand<<endl;
    
    

  }
  if (weapChoice == 2){
    weapChoice = lSaber;
srand(time(NULL)); //seed random number generator

  //generate 4 numbers
  
    {
      weapRand = rand()%4 + 1; //generate a random number from 1 to 4
if (weapRand == 1){
	cout<< "You hit Target A, 100 points"<<endl;
      	charaChoice = charaChoice + 100;
      }
      else if (weapRand == 2){
	cout<< "You hit Target B, 200 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (weapRand == 3){
	cout<< "You hit Target C, 300 points"<<endl;
      	charaChoice = charaChoice + 300;
      }
      else
      	cout<<"You missed the targets"<<endl;
      cout<<weapRand<<endl;

    }



  }
  // if the user chooses magic user will randomly generate #  
  // between 1-2 : if 1 increment 200 points if 2 decrement 100 points
  if (weapChoice == 3){
srand(time(NULL)); //seed random number generator
magicRand = rand()%2 + 1;
  //generate 2 numbers
  
  }
  //  magicRand = rand()%2 + 1; //generate a random number from 1 to 2
if (magicRand == 1){
	cout<< "Your magic worked, 200 points!!"<<endl;
      	charaChoice = charaChoice + 200;
      }
      else if (magicRand == 2){
	cout<< "Your magic didn't work, minus 100 points"<<endl;
      	charaChoice = charaChoice + 200;
      }
           
      
      cout<<magicRand<<endl;
  
      //weapChoice = magic;
  }
  while(weapChoice != 4);

magicRand is changed in line 74 and ONLY in line 74. If the user does not pick magic as a weapon, magicRand DOES NOT change and thus magicRand contains the same value it did the last time magic was chosen as a weapon. Lines 79 - 89 display whether the magic worked based on the value in magicRand from the last time that magic was chosen as a weapon. As I mentioned, lines 79 - 89 ALWAYS are executed, whether magic is picked or not. If these lines should only be executed when magic is picked, you need to change the placement of the bracket on line 77 and move it lower, after line 89.

Thanks for all your help, your advise has been very insightful and thanks for explaining things as you helped me out. I have problems with loops and (coming up next in class) functions!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.