Thread: C2065 Undeclared Identifier Error

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    23

    C2065 Undeclared Identifier Error

    I can't seem to figure out why I am get the error 2065: Undeclared identifier for 'PowerValue' and C2143:Syntax Error : Missing ';' before 'type' on line 13.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    void main ()
    {
    	int NumbertoMultiply;
    	int X; /*Answer after the number get multiplies a number by a factor 2 to the power n*/
    	printf("Please enter the number to multiply: ");
    	scanf_s("%d",NumbertoMultiply);
    
    
    	int PowerValue;
    	printf("Please enter the number for the power: ");
    	scanf_s("%d",PowerValue);
    
    
    	X = (NumbertoMultiply << PowerValue);
    
    
    	printf("Here is the value of X which was multiplied by your given number by a factor 2 to the power: %d",X);
    	
    
    
    }

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Assuming this is C and not C++, all of your variables need to be declared at the start of the function, so move int PowerValue; before or after the int X; .

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    23
    So I moved the int Powervalue; before int X;. I am getting new warnings i.e. C4700: Uninitialzied local variable 'PowerValue' Used and also get same error for 'NumbertoMultiply'

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That is because you forgot to pass a pointer to scanf_s on both occasions.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    May 2013
    Posts
    23
    Thank you! Laserlight

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error C2065: undeclared identifier
    By Sarge in forum Windows Programming
    Replies: 2
    Last Post: 02-19-2012, 03:22 PM
  2. error C2065: undeclared identifier
    By decxan in forum C++ Programming
    Replies: 2
    Last Post: 02-14-2011, 01:42 PM
  3. error C2065: undeclared identifier PLEASE HELP!
    By dyelax in forum C++ Programming
    Replies: 13
    Last Post: 10-12-2009, 11:50 AM
  4. error C2065 undeclared identifier
    By scott27349 in forum C++ Programming
    Replies: 6
    Last Post: 03-10-2002, 04:22 AM