compile time errors!!!!

This is a discussion on compile time errors!!!! within the C++ Programming forums, part of the General Programming Boards category; i dont get it the program looks fine but when i compile it give me errors which dont make any ...

  1. #1
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148

    Angry compile time errors!!!!

    i dont get it the program looks fine but when i compile it give me errors which dont make any sence. can someone help me, and tell me what is wrong. And another thing if i insert anything under the switch statement in case 2 it gives me a compile error as well!
    im running winxp and have bloodshed c++

    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <conio.h>
    class newUser //New User start
    {
     public:
     
     newUser();
     void setName(char userName);
     void setAmount(float money);
     void setIntrest(float rate);
     void setTime(int years);
     void setCurrency(char moneytype);
     void calculate(float amount, float intrest, int time, char currency);
     char getName();
     char getCurrency();
     float getAmount();
     float getIntrest();
     int getTime();
     
     private:
     
     char name;
     float amount;
     float intrest;
     int time;
     char currency;
    }; //end new user
    
    newUser::newUser()
    { 
     
    }
    
    
    void newUser::setName(char userName)
    {
     name = userName;
    }
    
    void newUser::setAmount(float money)
    {
     amount = money;
    }
    
    void newUser::setIntrest(float rate)
    {
     intrest = rate;
    }
    
    void newUser::setTime(int years)
    {
     time = years;
    }
    
    void newUser::setCurrency(char moneytype)
    {
     currency = moneytype; 
    }
    
    void newUser::calculate(float amount, float intrest, int time, char currency)
    {
     for(int x=0;x<time;x++)
     {
      amount = ((intrest/100)*amount)+amount;
      cout<<currency<<amount<<" <------Year "<<x<<endl<<endl;
     }
    }
    
    char newUser::getName()
    {
     return name;
    }
    
    char newUser::getCurrency()
    {
     return currency;
    }
    
    float newUser::getAmount()
    {
     return amount;
    }
    
    float newUser::getIntrest()
    {
     return intrest;
    }
    
    int newUser::getTime()
    {
     return time;
    }
    
    int main()
    {
     char quit;
     
     quit = '\0';  //quiting when q pressed
        while (quit != 'q')
        {   //start of program
         
         //decleration of variables
         
         int option;
         char userName;
         float money;
         float rate;
         int years;
         char moneytype;
              
         cout<<"|----------------|"<<endl;
         cout<<"|  Bank Program  |"<<endl;
         cout<<"|----------------|"<<endl<<endl<<endl;
         cout<<"1.  New User"<<endl;
         cout<<"2.  Previous User"<<endl;
         cout<<">>";
         cin>>option;
         if (option!=1 || option!=2)// check menu input
         {
         
          cout<<"Please choose only from the given options"<<endl<<endl;
          cout<<"1.  New User"<<endl;
          cout<<"2.  Previous User"<<endl;
          cout<<">>";
          cin>>option;
          
         }//end check menu
         
         switch (option)
         { //start of option menu
         
          case 1: 
          newUser User();
          cout<<endl<<"Please give us your name: ";
          cin>>userName;
          User.setName(userName);
          cout<<endl<<"How much money are you putting on the bank? ";
          cin>>money;
          User.setAmount(money);
          cout<<endl<<"What currency is the money (eg $)? ";
          cin>>moneytype;
          User.setCurrency(moneytype);
          cout<<endl<<"What is the intrest rate of the Bank? ";
          cin>>rate;
          User.setIntrest(rate);
          cout<<endl<<"How long are you keeping it there? ";
          cin>>years;
          User.setTime(years);
          cout<<endl<<endl<<"You are keeping "<<User.getCurrency()<<User.getAmount()<<" for "<<User.getTime()<<" years, at "<<User.getIntrest<<"% intrest rate";
          
           cout<<"Start amount: "<<User.getCurrency()<<User.getAmount;
           cout<<endl<<endl<<User.getIntrest()<<"% Intrest"<<endl<<endl<<"For "<<User.getTime()<<" Years"<<endl<<endl;
          //start of setting all the values
               
          cout<<endl<<endl<<"Thank you "<<User.getName()<<" for your time";
                      
          break;
          case 2: 
                break;      
          
         } //end of menu
        } //end of quitting when q pressed
        return 0;
    } //end of file

  2. #2
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    thank you, but unfortuanaltly i am not that smart and i have only done c++ programming for 2 months at home on my own so if you could fix it please and tell me how u fixed it that would be great.

    you dont offcource have too

    thank you again

  3. #3
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148

    Question

    i told you i am not that smart, im only 13 and if you could explain to me how to do that. What does global mean anyway?

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    global means that it is outside of main, up near where you #include your header files.

    i would not recommend this unless you are making it a const. reason for is it is very difficult to debug this type of run-time error. global variables and constants are able to be seen by any function in your .cpp file that it is above, so if it is up where you declare your #includes and before you declare functions/prototypes, it will be able to be seen by all your functions and main.

    also, i would recommend creating a separate header file and .cpp file for your class, and in your header file, if you don't already know, do this...

    Code:
    #ifndef CLASSNAME_H
    #define CLASSNAME_H
    
    class classname
    {
    
    };
    
    #endif
    Last edited by alpha; 11-17-2002 at 12:28 PM.

  5. #5
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    ok i seperated the two now it looks like this which makes it more readable but it gives me this error:

    48 request for member `setName' in `User', which is of non-aggregate type `newUser ()()'

    it gives me this for every member of the newUser class
    what does it mean


    bank.cpp:
    Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <conio.h>
    #include <newUser.h>
    
    int main()
    {
     char quit;
     
     quit = '\0';  //quiting when q pressed
        while (quit != 'q')
        {   //start of program
         
         //decleration of variables
         
         int option;
         char userName;
         float money;
         float rate;
         int years;
         char moneytype;
              
         cout<<"|----------------|"<<endl;
         cout<<"|  Bank Program  |"<<endl;
         cout<<"|----------------|"<<endl<<endl<<endl;
         cout<<"1.  New User"<<endl;
         cout<<"2.  Previous User"<<endl;
         cout<<">>";
         cin>>option;
         if (option!=1 || option!=2)// check menu input
         {
         
          cout<<"Please choose only from the given options"<<endl<<endl;
          cout<<"1.  New User"<<endl;
          cout<<"2.  Previous User"<<endl;
          cout<<">>";
          cin>>option;
          
         }//end check menu
         
         switch (option)
         { //start of option menu
         
          case 1: 
          newUser User();
          cout<<endl<<"Please give us your name: ";
          cin>>userName;
          User.setName(userName);
          cout<<endl<<"How much money are you putting on the bank? ";
          cin>>money;
          User.setAmount(money);
          cout<<endl<<"What currency is the money (eg $)? ";
          cin>>moneytype;
          User.setCurrency(moneytype);
          cout<<endl<<"What is the intrest rate of the Bank? ";
          cin>>rate;
          User.setIntrest(rate);
          cout<<endl<<"How long are you keeping it there? ";
          cin>>years;
          User.setTime(years);
          cout<<endl<<endl<<"You are keeping "<<User.getCurrency()<<User.getAmount()<<" for "<<User.getTime()<<" years, at "<<User.getIntrest<<"% intrest rate";
          
           cout<<"Start amount: "<<User.getCurrency()<<User.getAmount;
           cout<<endl<<endl<<User.getIntrest()<<"% Intrest"<<endl<<endl<<"For "<<User.getTime()<<" Years"<<endl<<endl;
          //start of setting all the values
               
          cout<<endl<<endl<<"Thank you "<<User.getName()<<" for your time";
                      
          break;
          case 2: 
          
          break;      
          
         } //end of menu
        } //end of quitting when q pressed
        return 0;
    } //end of file
    newUser.h:
    Code:
    #ifndef newUser_H
    #define newUser_H
    
    class newUser //New User start
    {
     public:
     
     newUser();
     void setName(char userName);
     void setAmount(float money);
     void setIntrest(float rate);
     void setTime(int years);
     void setCurrency(char moneytype);
     void calculate(float amount, float intrest, int time, char currency);
     char getName();
     char getCurrency();
     float getAmount();
     float getIntrest();
     int getTime();
     
     private:
     
     char name;
     float amount;
     float intrest;
     int time;
     char currency;
    }; //end new user
    
    newUser::newUser()
    { 
     
    }
    
    
    void newUser::setName(char userName)
    {
     name = userName;
    }
    
    void newUser::setAmount(float money)
    {
     amount = money;
    }
    
    void newUser::setIntrest(float rate)
    {
     intrest = rate;
    }
    
    void newUser::setTime(int years)
    {
     time = years;
    }
    
    void newUser::setCurrency(char moneytype)
    {
     currency = moneytype; 
    }
    
    void newUser::calculate(float amount, float intrest, int time, char currency)
    {
     for(int x=0;x<time;x++)
     {
      amount = ((intrest/100)*amount)+amount;
      cout<<currency<<amount<<" <------Year "<<x<<endl<<endl;
     }
    }
    
    char newUser::getName()
    {
     return name;
    }
    
    char newUser::getCurrency()
    {
     return currency;
    }
    
    float newUser::getAmount()
    {
     return amount;
    }
    
    float newUser::getIntrest()
    {
     return intrest;
    }
    
    int newUser::getTime()
    {
     return time;
    }
    
    #endif

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by devour89

    newUser.h:
    Code:
    #ifndef newUser_H
    #define newUser_H
    
    class newUser //New User start
    {
     public:
     
     newUser();
     void setName(char userName);
     void setAmount(float money);
     void setIntrest(float rate);
     void setTime(int years);
     void setCurrency(char moneytype);
     void calculate(float amount, float intrest, int time, char currency);
     char getName();
     char getCurrency();
     float getAmount();
     float getIntrest();
     int getTime();
     
     private:
     
     char name;
     float amount;
     float intrest;
     int time;
     char currency;
    }; //end new user
    
    //end the newUser.h file here.  make a newUser.cpp file and #include the header file in your .cpp file.  then include your .cpp file into your project.  try this...i think the compiler may just not be able to recognize the prototypes the way you have it.
    
    newUser::newUser()
    { 
     
    }
    
    
    void newUser::setName(char userName)
    {
     name = userName;
    }
    
    void newUser::setAmount(float money)
    {
     amount = money;
    }
    
    void newUser::setIntrest(float rate)
    {
     intrest = rate;
    }
    
    void newUser::setTime(int years)
    {
     time = years;
    }
    
    void newUser::setCurrency(char moneytype)
    {
     currency = moneytype; 
    }
    
    void newUser::calculate(float amount, float intrest, int time, char currency)
    {
     for(int x=0;x<time;x++)
     {
      amount = ((intrest/100)*amount)+amount;
      cout<<currency<<amount<<" <------Year "<<x<<endl<<endl;
     }
    }
    
    char newUser::getName()
    {
     return name;
    }
    
    char newUser::getCurrency()
    {
     return currency;
    }
    
    float newUser::getAmount()
    {
     return amount;
    }
    
    float newUser::getIntrest()
    {
     return intrest;
    }
    
    int newUser::getTime()
    {
     return time;
    }
    
    #endif
    oh and remember to #include your header file in double quotes...
    Last edited by alpha; 11-18-2002 at 03:51 PM.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    ok here's the problem. when you declare newUser in main as

    Code:
    newUser User();
    this is wrong. you need to declare this as...

    Code:
    newUser User;  //note the lack of parentheses
    i can't believe i didn't catch this earlier...now i believe you can leave it all in one file, but splitting it up is cleaner...

    you will have to overload cin and cout to be able to cin and cout stuff of your class. this is why i tend to split files up, it keeps things in order...

    you need to overload these functions because your new class is not a built in datatype...

    hope this helps...if you need pointers (pun not intended) on how to overload cin and cout...just ask...although im still learning how to program in c++, i really don't know that much, but i recently learned how to, so i think i should be able to help...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile errors with overloading >> operators
    By GMHummerH1 in forum C++ Programming
    Replies: 1
    Last Post: 12-19-2004, 06:13 PM
  2. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 01:21 PM
  3. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  4. Compile Errors Due to STL & Iterator
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 12-02-2001, 09:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21