I'm writing a pennies game in which a player and the computer take coins from a pile until only one remains. The trouble is I keep getting an error saying "warning C4700: uninitialized local variable 'nuCoins' used" though I thought after the user input a value it would be.
Any help would be much appriciated.

#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std ;
 
       
  
void main()

{
  

  srand((unsigned)time(0)) ;

   int number ;
   int gameStrtNo ;
   int lowest = 1, highest = 5 ;
   int range =(highest - lowest) + 1 ;

     for(int index = 0 ; index < 200 ; index++)

     {
        int randNo = lowest+int(range*rand()/(RAND_MAX + 1.0)) ; 
	 

	 
   


   cin >> gameStrtNo ;

  int nuCoins = 50 - (number || randNo); 

   if (gameStrtNo <=5)
   {
	   cout << "Player goes first!\n" ;
           cout << "Pick between 1 and 5 coins.\n" ;
	   cin >> number ;
	   cout << "There are "<<nuCoins<<" left.\n" ;  //ERROR HERE
   }

   else
   {
	    cout << "Computer goes first!\n" ;
            cout << "Computer picked "<<randNo<<" coins.\n" ;
            cout << "There are "<<nuCoins<<" left.\n" ;
   }
		
 


	 }      
  
 }

Line 33 - number is not initialized and you are using number to initialize nuCoins , so you are initializing nuCoins , but you have no idea what you're initializing it to since number is not initialized. number is initialized in line 39 with the cin statement, but you're intializing nuCoins BEFORE that line.

what are you trying to do here :

int nuCoins = 50 - (number || randNo);

Do you really mean that nuCoins will only be 49 or 50, provided that both contain some value ( which is your problem by the way, as pointed out ).

Ah righttt! Thanks very much :)

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.