Thread: Undeclared identifier major problem

  1. #16
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Yes Its like magic, isn't it?

    This is the point of a "variable". It's a "variable"! That is, its not constant, it changes, it varies. At any given time in the program, variable Resistance contains some value, but the value it contains depends on either where you are in the program or what the user entered, or what was read from a file, or what was read from a socket, etc.

    A lot of Computer Science (and therefore programming, as it is only a subfield of Computer Science) comes from other fields, including mathematics. For example, the function
    Code:
    f(x) = 5x + 2
    Is a function named "f", taking parameter named "x" of (implicit) type "real number". The body of the function returns some calculation, namely "5x + 2". The result of this of course depends on and requires knowing what the value of "x" is. If "x" is 1 (say, the user input), the result is 7.

  2. #17
    Registered User
    Join Date
    Mar 2010
    Posts
    11
    Thank you so much for your help my lecturer has gone on holiday...damn easter! and the work is in for monday...Right this is where i am now im still getting the same error, one example:
    1>c:\data\jacks1d\my documents\visual studio 2008\projects\rlc project 2\rlc project 2\rlcseriescircuit.cpp(28) : error C2065: 'Inductance' : undeclared identifier

    My simulation cpp file NOW looks like this:
    Code:
    //Simulation C++ File
    //Created by Daniel Jackson
    
    #include <iostream>
    #include <iomanip>
    using namespace std;
    #include <cmath>
    using std::pow;
    using std::log;
    using std::setprecision;
    #include <string>
    using std::string;
    using std::getline;
    
    #include "Simulation.h" //include Simulation Class Definition
    #include "RLCSeriesCircuit.h" //include RLCSeriesCircuit class defniition
    
    
    
    
    void Simulation::Userdisplay () //1st Function (User inputs)
    {
    	
        cout << "**********************************************************\n"; //user display (start)
    	cout << "* 205SE Assignment                                       *\n";
    	cout << "* Created by Daniel Jackson (SID: 1641552)               *\n";
    	cout << "* This program simulates the behaviour of an             *\n";
    	cout << "* RLC circuit based on user inputs                       *\n";
    	cout << "**********************************************************\n";
    
    	cout << "\nRLC Series circuit Simulation"; //Program Title (Stage 3 of Activity)
    	cout << "\nEnter the values for the circuit components:\n";
    
    
    	cout << "\nPlease enter Resistance value[Ohms] -> "; //Prompt for R (Stage 4 of Activity)
    	cin >> Resistance; //Read in R (Stage 4 of Activity)
    
        cout << "\nPlease enter Inductance value[H] -> "; //Pompt for L (Stage 4 of Activity)
    	cin >> Inductance; //Read in L (Stage 4 of Activity)
     
    	cout << "\nPlease enter Capacitance value[F] -> "; //Prompt for C (Stage 4 of Activity)
    	cin >> Capacitance; //Read in C (Stage 4 of Activity)
    
    	cout << "\nEnter the operating conditions:\n";
    	
    	cout << "Enter supply Voltage [V] -> "; //prompt for supply voltage
    	cin >> VS; //Read in supply Voltage
    
    	cout << "Enter Min Supply frequency [Hz] -> "; //prompt for minimum supply frequency
    	cin >> MinFreq; //Read in Minimum Frequency
    
    	cout << "Enter Max supply frequency [Hz] -> "; //prompt for maximum frequency
    	cin >> MaxFreq; //Read in Maximum Frequency
    
    	cout << "Enter No. of frequency steps required -> "; //prompt for number of freq steps
    	cin >> Freqsteps;
    
    	RLC_Series_Cct circuit;
    	circuit.Incrementloop(Resistance, Inductance, Capacitance)
      
    }
    Is there still something i need to do? as even tho im passing them here is an argument when calling the function they are still not being recognised? maybe i need to do something with the Incrementloop() function from within the definition also? The last coursework was so much easier...it asked me to do exactly the same thing but with just one class for it all....

    Note: i understand there are many more variables to sort and add to arguement list...but i will look at adding them once i got the first few working.

  3. #18
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Did you change the h and cpp files for Circuit to reflect the change in your function? They of course must have been modified, so that you change the function to accept the various parameter(s), as stated before. That is, change it from something like
    Code:
    void myFunction()
    {
    //...
    }
    to
    Code:
    void myFunction(int resistance)
    {
    //...
    // do something with "resistance"
    }

  4. #19
    Registered User
    Join Date
    Mar 2010
    Posts
    11
    You, My friend deserve a Knighthood! the program is running! I will post you my working code now, theres a few bits of tidying to do but if you wanna give it the once over to check what ive done is correct that would be very helpful indeed.
    Code:
    //Header file for RLC Series CIrcuit
    //Created by Daniel Jackson
    #include <iostream>
    using namespace std;
    
    
    class RLC_Series_Cct
    {
    public:
    	void Incrementloop(double Resistance, double Capacitance, double Inductance, double MinFreq, double MaxFreq, double VS);
    private:
    	double actualFreq;
    	double Z;
    	double I;
    	double VR;
    	double NF;
    	double XL;
    	double XC;
    	double VOVR;
    	int iteration;
    	int Maxstep;
    		
    };
    Code:
    //RLC Series Circuit C++ File
    //Created by Daniel Jackson
    
    #include <iostream>
    #include <iomanip>
    using namespace std;
    #include <cmath>
    using std::pow;
    using std::log;
    using std::setprecision;
    #include <string>
    using std::string;
    using std::getline;
    
    #include "Simulation.h"
    #include "RLCSeriesCircuit.h"
    
    const double pi = 3.1415926535; //Global constant
    
    
    
    void RLC_Series_Cct::Incrementloop(double Resistance,double Capacitance, double Inductance, double MinFreq, double MaxFreq, double VS) //2nd function (calculation with for loop)
    	{
    		
    		cout << right; // one time exectution
    		cout.fill ('*');
    		
    		NF = (((2*pi*sqrt(Inductance*Capacitance))/1)); //Calculate Natural Frequency 	
    		Maxstep = ((log10(MaxFreq) - log10(MinFreq))/(0.1)); //incerement calculation
    		cout << "Voltage ratio plot at each frequency step:\n\n"; //introduces chart
    			
    				for (iteration= 1; iteration<= Maxstep; iteration++) //for loop begins 
    				{
    				actualFreq = (MinFreq * pow(10.0, (0.1 * iteration))); // plot Voltage ratio
    				XL = (2 * pi * actualFreq * Inductance); //Calculation 
    				XC = (1/ (2 * pi * actualFreq * Capacitance)); //Calculation 
    				Z = (sqrt(Resistance * Resistance + (XL - XC) * (XL - XC))); //Calculation 
    				I = (VS / Z); //Calculation 
    				VR = (I * Resistance); //Calculation 
    				VOVR = (VR / VS); //Calculation 
    				 	
    				cout << setw(VOVR * 100) << actualFreq << setprecision (2) << endl;
    				}
    				
    			
    			cout << "\nNatural frequency of circuit = " << NF << setprecision( 2 ); //outputs Natural Frequency to user
    
    }
    So ive added in all the variables and it seems to work, i cant believe something this simple has given me such a headache...spose its easy when you know how though.

  5. #20
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    I certainly don't remember any EE stuff, and have my own studying to do so I cant really focus on this to understand and/or critique it. In programming, when you're doing or forced to do something that seems unnatural, it's probably because what you've written is poorly designed or incorrect altogether.

    One thing that stands out is all of the arguments being passed to this function, which, from the name "IncrementLoop", seems to supposed to do one single simple thing. Just from the number of arguments being passed, makes it seem complex which contradicts the assumption that its a simple function. Of course I can be wrong and maybe this is actually a good way to design it. If its working then you can probably stick with it. If you re-think it and come up with a better or more natural way to do the same thing, then re-write it that way. In either case, you could just wait until you have an OO analysis and design or software engineering course, to get familiar with good designs.

    Anyway, your welcome.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM