Thread: I cant find the error

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    3

    Unhappy I cant find the error

    whats wrong with this progam

    Code:
    #include<iostream.h>
    class carADT{
    private:
    static int fuel,water,oil;
    public:
     carADT();
     carADT(int ff=1000,int ww=1000,int oo=1000);
     int swOn();
     int drive();
     int stop();
     int setspeed();
     void service();
     void fillTank();
     };
     carADT::carADT(){
     fuel=water=oil=0;
     }
     carADT::carADT(int ff,int ww,int oo){
     fuel=ff;
     water=ww;
     oil=oo;
     }
     carADT::int swOn(){
     cout<<"you can drive now:\n";
      return 1;
     }
    
     carADT::int drive(){
     carADT d;
     int x,z;
    x=d.swOn();
    d.setspeed();
    if(x==1){
     while((z=d.stop)!=0){
     for(int c=1000;c>0;c--){
      fuel--;
      water--;
      oil--;
      }}}
      if(fuel==water==oil==0)
      return 1;
      else
      return 0;
      }
      carADT::int stop(){
      carADT s;
      int z;
      w=s.speed();
      z=s.drive();
      if(z==1||w==0)
      return 0;
      else{
      s.switchOn(0);
      return 1;
      }
     carADT::int setspeed(){
     int sp,spd=0;
     cout<<"what is the speed you want:\n"<<endl;
     cin>>sp;
     while(spd!=sp){
     spd++;
     cout<<"the speed is "<<spd<<endl;
     }
     if(sp==spd==0)
     return 0;
     }
     carADT::void service(){
     fuel=oil=water=1000;
     }
     carADT::void fillTank(){
     if(fuel!=2000){
     fuel=2000;
     }
     int main(){
     int y,r;
     char s,f;
     cout<<"Do you want to drive:\n";
     cin>>y;
     if(y==1){
     cout<<"do you want to stop: enter y/n\n";
     cin>>s;
     if(s=='y')
     D.stop();
     else{
     while(!(D.stop()){
     r=D.drive();
     cout<<"do you want to stop\n";
     cin>>s;
    if(s=='y')
     D.stop(); }}
     if(r==1)
     D.service();
     }
     cout<<"do you want to fill the tank:\n";
     cin>>f;
     if(f=='y')
     D.fillTank();
    
     return 0;
     }
    Please use [code][/code]Tags

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    How about this: YOU tell US what's wrong. Then post again. We can't waste our time sifting through pages of code. Narrow it down a bit.

    Use code tags.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    This I belive is wrong,
    Code:
    carADT::int drive(){
    try this instead
    Code:
    int carADT::drive(){
    Wouldnt hurt to add error message.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Or,

    1. get school assignment
    2. read it through once
    3. post on cprogramming.com for answer

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    To repeat Salem's point...

    Here's something I posted last month:
    Start small... Just write enough code so that it compiles. Add a little code at a time, test-compiling and test-running as you proceed. This way you will know right away where the problems are.

    It takes a bit of practice to learn how to sequence your program development so that it's testable as you go along. Usually, the user interface, or input/output is started first (but maybe not finalized) so you can see what your program is doing.

    Programming is difficult, and every programmer test-compiles and test-runs during development. Beginners should test-compile every line or two! More experienced programmers might only test-compile every "page" or so, depending on how familiar they are with the particular functions they are using, etc.

  6. #6
    ___
    Join Date
    Jun 2003
    Posts
    806
    If you test run each line wouldn't you get an error every line until the main closing bracket?
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    You build a basic skeleton, beginning with the your nice 'int main() { }' (preferably with some extra whitespace). Once you have a functional skeleton, you add functionality a couple lines at a time and recompile.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  8. #8
    ___
    Join Date
    Jun 2003
    Posts
    806
    Oh ok. I think I'm going to try that sometime.
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

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. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM