Help needed ASAP, please

Discussion in 'C++' started by Lunarek, Jul 12, 2009.

  1. Lunarek

    Lunarek New Member

    Joined:
    Jul 12, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hi everyone, I wrote a program that's needed in an hour or so, and I have tons of errors there, please help me complete it, it's due today .
    The program is basically a program that'd convert any amount entered in dollars and convert to either Euro,RIY,JPY.
    What confuses me is that we HAVE to use classes and at least six functions, and so far my code looks good but it would give me bunch of gibberish errors.
    PLEASE HELP ME IT'S A SUMMER COURSE T.T

    here's the code hope i get help soon, Lunarek




    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    class currencies 
    {
    public:
    
        
    void USDtoRIY ();
    void getUSDtoYen ();
    void USDtoEuro ();
    void Currencyrates ();
    void Currencyinfo ();
    
    void printJPY ();
    void printRIY ();
    void printEURO ();
     private:
      
    
    
    };
    
    int main()
    {
        double Yen =   127.633;
        double Euro =  1.39009  ;
        double USD =   1.0; 
        double RIY =   0.2667;  
        double amt;
        
        double conamt ;
    
    double JPY       = 127.633;
      double USdollars = 1.0 ;
      double Riyals    = 0.2667;
      double Euros     = 1.39009;
    
        string choice;
        string choice2;
        
    
     cout << "Thanks for using the USD currency converter program.\nThis program allows you to convert only from USD to Euro,JPY,and RIY." <<endl <<endl;
    cout << "Before we start the program, I would like you to know the basic commands that\nyou could use to interact with this program\n" <<endl;
    
     cout << "commands to use are as follows\n -JPY = convert your USD to Yen \n -RIY = convert your USD to Riyals \n -EURO = convert your USD to European Euros" <<endl << endl;
    cout << "Also you can type in 'Rates' to get information of each currencies' rate, and \ntype 'Cinfos' to get informations about each currency\n please note that the program is case sensitive so make sure you write the commands exactly as they appear in the instructions." <<endl << endl ;
    cout << "so now to start the program please type in 'Start', and when you're done you can exit the program by typing 'Exit'." <<endl<<endl;
        cin >> choice2;
    
        while ( choice2 == "Start" )
        {
            cin >> choice;
            if( choice == "JPY")
                cout << "Enter the Dollars amount" <<endl;
                cin >> amt;
                currencies.printJPY();
            else if (choice == "RIY" )
            cout << "Enter the Dollars amount" <<endl;
            cin >> amt;
            currencies.printRIY ();
        }
        return 0;
    }
    
    
    void currencies: :getUSDtoYen (double USdollars,double JPY, double& amt, double conamt)
    {
          conamt = (amt * USdollars) / JPY; //change the conversion rate
           
    
    }
    void currencies:: printJPY ()
    {
     cout << "The amount in JPY is equal to" << conamt<< endl;
    }
    
    void currencies.USDtoEURO (double USD, double Euro);
    { 
        conamt = (amt*USD) * EURO; //change the conversion rate.
    
        
    }
    void currencies: : printEURO ()
    {
     cout << "The amount in EURO is equal to" << conamt<< endl;
    }
    void currencies. USDtoRiyal (double RIY, double USD, double conamt, double amt)
    {
        conamt = (amt*USD)/RIY;//change the conversion rate.
    
        
    }
    void currencies:: printRIY ();
    {
        cout << "The amount in RIY is equal to" << conamt<< endl;
    }
     
    Last edited by a moderator: Jul 13, 2009
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Why do you need the user to type Start to start the program? Wasn't running it enough to convince you that they wanted it to run? (I point this out because I absolutely hate "are you sure"-style messages. Yes I'm sure, otherwise I wouldn't have typed that command would I.)

    I guess your errors are along the lines of "conamt not defined" and "amt not defined", and you're looking at main and thinking "yes they are defined". They're not defined for class currencies, hence the errors. Variables defined in a function are effectively "private" to that function and nobody else has access, except where you pass pointers to the variables, or where you pass the variables' values to called functions.

    So here's my suggestion: define amt and conamt (if needed) in the class, then just call functions in the class from main. Have a member function that prompts for input, and a function that prompts for the currency to convert to, then depeding on the input given either call a function to do the conversion directly, or pass something back to main so that it can call the conversion function. It's up to you if the conversion function displays the output or leaves it to main to call a function that displays the output.
     
  3. Lunarek

    Lunarek New Member

    Joined:
    Jul 12, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    "Why do you need the user to type Start to start the program? Wasn't running it enough to convince you that they wanted it to run? (I point this out because I absolutely hate "are you sure"-style messages. Yes I'm sure, otherwise I wouldn't have typed that command would I.)"
    Trust me I'm as frustrated as you are, our professor is the one who asked for that, and gosh I can't even undrestand a word he says, he has the world's terrible accent ever.


    when I do define the amt, and conamt in the currencies class, they has to be changed to double :/

    "Have a member function that prompts for input, and a function that prompts for the currency to convert to"
    aren't those already there, I mean the functions...
    thanks for the quick reply :)
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    No, you only have display and convert functions.
    A member function is a member of the class such as currencies::printEURO(). main is not a member function, it's a global function.

    Also I see you're using variable syntax for member functions which will probably generate more errors. The correct syntax is classname, no space, colon, no space, colon, no space, function name, for example currencies::printEURO(). All of the following are wrong and why:

    currencies: :getUSDtoYen -> no space between the colons
    currencies:: printJPY -> no space after the colons
    currencies.USDtoEURO -> two colons, not dot
    currencies: : printEURO -> no spaces between or after the colons.
     
  5. Lunarek

    Lunarek New Member

    Joined:
    Jul 12, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    I made some changes, and apparently the errors has reduced to less, here's the updated code

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    class currencies 
    {
    public:
    
    	
    void USDtoRIY ();
    void getUSDtoYen (double USdollars,double JPY, double& amt, double conamt);
    void USDtoEuro ();
    void Currencyrates ();
    void Currencyinfo ();
    
    void printJPY ();
    void printRIY ();
    void printEURO ();
     private:
      
    double amt;
    	
    	double conamt ;
    
    };
    
    int main()
    {
    	currencies mycurrency;
    	
    	double Yen =   127.633;
    	double Euro =  1.39009  ;
    	double USD =   1.0; 
    	double RIY =   0.2667;  
    	
    
    	double JPY       = 127.633;
        double USdollars = 1.0 ;
    	double Riyals    = 0.2667;
    	double Euros     = 1.39009;
    
    	string choice;
    	string choice2;
    	
    
    	cout << "Thanks for using the USD currency converter program.\nThis program allows you to convert only from USD to Euro,JPY,and RIY." <<endl <<endl;
    	cout << "Before we start the program, I would like you to know the basic commands that\nyou could use to interact with this program\n" <<endl;
    
    	cout << "commands to use are as follows\n -JPY  = convert your USD to Yen \n -RIY  = convert your USD to Riyals \n -EURO = convert your USD to European Euros" <<endl << endl;
    	cout << "Also you can type in 'Rates' to get information of each currencies' rate, and \ntype 'Cinfos' to get informations about each currency\n please note that the program is case sensitive so make sure you write the commands exactly as they appear in the instructions." <<endl << endl ;
    	cout << "so now to start the program please type in 'Start', and when you're done you can exit the program by typing 'Exit'." <<endl<<endl;
    	cin >> choice2;
    
    	while ( choice2 == "Start" )
    	{
    		cin >> choice;
    		if( choice == "JPY")
    		{
    			cout << "Enter the Dollars amount" <<endl;
    			cin >> amt;
    			mycurrency.printJPY();
    		}
    		else if (choice == "RIY" )
    		cout << "Enter the Dollars amount" <<endl;
    		cin >> amt;
    		mycurrency.printRIY ();
    	}
    	return 0;
    }
    
    
    void currencies::getUSDtoYen (double USdollars,double JPY, double& amt, double conamt)
    {
    	  conamt = (amt * USdollars) / JPY; //change the conversion rate
           
    
    }
    void currencies::printJPY (double &conamt)
    {
     cout << "The amount in JPY is equal to" << conamt<< endl;
    }
    
    void currencies::USDtoEURO (double USD, double Euro);
    { 
    	conamt = (amt*USD) * EURO; //change the conversion rate.
    
    	
    }
    void currencies::printEURO ()
    {
     cout << "The amount in EURO is equal to" << conamt<< endl;
    }
    void currencies::USDtoRiyal (double RIY, double USD, double conamt, double amt)
    {
    	conamt = (amt*USD)/RIY;//change the conversion rate.
    
    	
    }
    void currencies::printRIY ();
    {
    	cout << "The amount in RIY is equal to" << conamt<< endl;
    }
    
    these are the errors:
    Error 1 error C2065: 'amt' : undeclared identifier
    Error 2 error C2065: 'amt' : undeclared identifier
    Error 3 error C2511: 'void currencies::printJPY(double &)' : overloaded member function not found in 'currencies'
    Error 4 error C2039: 'USDtoEURO' : is not a member of 'currencies'
    Error 5 error C2065: 'conamt' : undeclared identifier
    Error 6 error C2065: 'amt' : undeclared identifier
    Error 7 error C2065: 'EURO' : undeclared identifier
    Error 8 error C2039: 'USDtoRiyal' : is not a member of 'currencies'


    obviously my problem is how to get all the variables and functions to be connected........
    Lunarek
     
    Last edited by a moderator: Jul 13, 2009
  6. Lunarek

    Lunarek New Member

    Joined:
    Jul 12, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    all of the :P face are actually ": p" just so you know :/
     
  7. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    You can fix that by
    (a) posting code in code blocks, and
    (b) using "disable smileys" in Advanced mode
     
  8. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    amt needs to be defined where you're using it, so if you're using it in main then you have to declare it in main. What I was trying to get at before is that you don't use it at all in main but delegate references to it into the class.

    printJPY is declared as void printJPY (); but you're trying to use it as if it has a parameter. Either add the parameter to the definition or don't try to use it with a parameter.

    The error 'USDtoEURO' : is not a member of 'currencies' is correct; there is no function USDtoEURO.

    The error "'EURO' : undeclared identifier" is correct; there is no such identifier.

    The error "'USDtoRiyal' : is not a member of 'currencies'" is correct; there is no such member function currencies::USDtoRiyal
     
  9. Lunarek

    Lunarek New Member

    Joined:
    Jul 12, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    I made the following changes to the program and it still gives me errors

    I declared the doubles inside of private class, but they dont seem to be working
    here's the code :

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    using namespace std;
    
    class currencies 
    {
    public:
    void conUSDtoRIY (double ,double , double, double);
    void getUSDtoRIY(double&, double&)const;
    
    void getUSDtoYen (double&, double&) const;
    void conUSDtoYen (double ,double , double, double);
    
    void conUSDtoEuro (double,double,double,double);
    
    void getUSDtoEuro (double&,double&)const;
    
    void printJPY ();const
    void printRIY ();const
    void printEURO ();const
    
     private:
    	 double Yen = 127.633;
    	 double Euro =  1.39009  ;
    	 double USD =   1.0; 
    	 double RIY =   0.2667;  
      
    	 double  amt;
    	 double  conamt ;
    
    };
    
    int main()
    {
    	currencies mycurrency;
    	
    	double amtx;
    	double amtcon;
    	string choice;
    	string choice2;
    
    	cout << "Thanks for using the USD currency converter program.\nThis program allows you to convert only from USD to Euro,JPY,and RIY." <<endl <<endl;
    	cout << "Before we start the program, I would like you to know the basic commands that\nyou could use to interact with this program\n" <<endl;
    
    	cout << "commands to use are as follows\n -JPY  = convert your USD to Yen \n -RIY  = convert your USD to Riyals \n -EURO = convert your USD to European Euros" <<endl << endl;
    	cout << "Also you can type in 'Rates' to get information of each currencies' rate, and \ntype 'Cinfos' to get informations about each currency\n please note that the program is case sensitive so make sure you write the commands exactly as they appear in the instructions." <<endl << endl ;
    	cout << "so now to start the program please type in 'Start', and when you're done you can exit the program by typing 'Exit'." <<endl<<endl;
    	cin >> choice2;
    
    	while ( choice2 == "Start" )
    	{
    		cin >> choice;
    		if( choice == "JPY")
    		{
    			cout << "Enter the Dollars amount" <<endl;
    			cin >> amtx;
    			mycurrency.printJPY();
    			
    		}
    		else if (choice == "RIY" )
    		cout << "Enter the Dollars amount" <<endl;
    		cin >> amtx;
    		mycurrency.printRIY ();
    	}
    	else if (choice == "Euro" )
    		cout << "Enter the Dollars amount" << endl;
    		cin >> amtx;
    		mycurrency.printEURO ();
    	return 0;
    }
    
    //functions.
    
    void currencies::getUSDtoYen (double& amtx, double& amtcon)const 
    {
    	  amt = amtx;
    	  conamt = amtcon;
    }
    void currencies::conUSDtoYen (double amt ,double conamt, double Yen, double USD)
    {
    	conamt = (amt*USD)/Yen //currency conversion.
    }
    
    void currencies::printJPY (double &conamt)
    {
     cout << "The amount in JPY is equal to" << conamt<< endl;
    }
    
    void currencies::getUSDtoEuro (double& amtx, double& amtcon)
    { 
    	 amt = amtx;
    	  conamt = amtcon; 
    }
    void currencies ::conUSDtoEuro (double amt, double conamt,double Euro, double USD)
    {
     conamt = (amt * USD)*Euro;
    }
    void currencies::printEURO ()
    {
     cout << "The amount in EURO is equal to" << conamt<< endl;
    }
    
    void currencies::getUSDtoRiyal (double& amtx, double& amtcon)
    {
    	amt = amtx;
    	  conamt = amtcon; 
    }
    void currencies::USDtoRIY(double, double, double, double)
    {
    	conamt = (amt*USD)/RIY;
    }
    
    void currencies::printRIY ()
    {
    	cout << "The amount in RIY is equal to" << conamt<< endl;
    }

    can you copy it to your VS and see what's the problem????
    thanks.......
     
    Last edited by a moderator: Jul 13, 2009
  10. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    @ Lunarek : Please post your code within code blocks.
    You can do that by keeping the code within [noparse]
    Code:
     ..<your code>.. 
    [/noparse]
    .

    Your code has so many fundamental mistakes. I think you need to strengthen your C++ basics.
     
  11. Lunarek

    Lunarek New Member

    Joined:
    Jul 12, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    but why doesn't it accept the double inside of private class?
    Lunarek
     
  12. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    I think you're probably confusing yourself by trying to develop the whole program at once. Take just one part, e.g. just the "if (choice == "JPY")" block, implement that and get it working.

    Then add the rest bit by bit, testing as you go along.

    Also when you post code with errors, state what the errors are. Often code can be fixed by looking at the errors, but not stating what they are means I have to try and guess, which is more work, or I have to muck about creating a VS project to run it in, which is more mucking about, so just post the errors and if I need to create a VS project to answer your questions then that's my choice.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice