Car Simulation

okay i been working on this program for days and i get these errors when i run my program im using visual studio 2010.
the errors are error LNK2001:unresolved external symbol"public: FuelGaugeTest.obj
error LNK1120:1 unresolved externals CarSimulater.exe
Here is my program.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
#include <iostream>  
#include <cstdlib>  
#include <string>
using namespace std; 
class FuelGauge
{
private:
	int currentAmountOfFuel;
public:
	FuelGauge(int gallons){
currentAmountOfFuel=gallons;
	}
	FuelGauge();
	int getCurrentAmountOfFuel()
	{
		
		return currentAmountOfFuel;
	}
	void incrementFuelTank(){

        if (currentAmountOfFuel< 15 )

            currentAmountOfFuel++;
    }
	void decrementFuelTank()
	{
		if(currentAmountOfFuel>0)
			 currentAmountOfFuel--;
	}

};
#pragma once
#include <iostream>  
#include <cstdlib>  
#include <string>
#include "FuelGauge.h"

class Odometer
{
private:
	int currentMileage;
	FuelGauge *fuelG;
public:
	Odometer(int miles,FuelGauge *f){

    currentMileage = miles;
	fuelG= f;
  }
	
int getCurrentMileage(){
	return currentMileage;
}
void incrementcurrentMileage(){

        if(currentMileage < 999999 )
           currentMileage++;
		 if (currentMileage == 999999)
			 currentMileage = 0;
}
void decrementcurrentMileage(){
	 if (currentMileage > 24 )
		 currentMileage--;}
	

		
	 
	 };
#include <iostream>  
#include <cstdlib>  
#include <string>
#include "FuelGauge.h"
#include "Odometer.h"
using namespace std; 

int main()
{
	
		FuelGauge fuelG;

        Odometer odm(0,&fuelG);

 

		
      
		for(int i=0; i<15; i++)
			fuelG.incrementFuelTank();
       

 

       while (fuelG.getCurrentAmountOfFuel() > 0) 
	   {
 
			odm.incrementcurrentMileage();
	
			cout<<"Mileage: "<<odm.getCurrentMileage()<<endl;
		
	

         cout<<"Fuel level"<< fuelG.getCurrentAmountOfFuel()<<" gallons"<<endl;
			
		}
	   return 0;
	    system("pause");
}
Last edited on
Don't use system("PAUSE"), use cin.get()
okay I took out the default constructor and I passed an argument to the constructor and use cin.get()
1
2
3
FuelGauge();
FuelGauge fuelG(15);

the programs runs but its spitting out information really fast and keeps going.
1
2
3
4
5
6
7
8
9
10
11
12
while (fuelG.getCurrentAmountOfFuel() > 0) 
	   {
 
			odm.incrementcurrentMileage();
	
			cout<<"Mileage: "<<odm.getCurrentMileage()<<endl;
		
	

         cout<<"Fuel level"<< fuelG.getCurrentAmountOfFuel()<<" gallons"<<endl;
			
		}


It's getting stuck here, isn't it?
Yes i used break points and its just stuck in the while loop but I can't figure out the problem.
As far as I can tell (you're program's hard to follow) currentAmountOfFuel is never getting changed, so you're gonna be stuck in there forever.
okay I changed some stuff in my program i'm trying to put in a pointer function to stop the while loop from being stuck but its still not working can someone please help me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
#include <iostream>  
#include <cstdlib>  
#include <string>
using namespace std; 
class FuelGauge
{
private:
	int currentAmountOfFuel;
public:
	FuelGauge(int gallons){
currentAmountOfFuel=gallons;
	}
	//FuelGauge();
	int getCurrentAmountOfFuel()
	{
		
		return currentAmountOfFuel;
	}
	void incrementFuelTank(){

        if (currentAmountOfFuel< 15 )

            currentAmountOfFuel++;
    }
	void decrementFuelTank()
	{
		if(currentAmountOfFuel>0)
			 currentAmountOfFuel--;
	}

};
#pragma once
#include <iostream>  
#include <cstdlib>  
#include <string>
#include "FuelGauge.h"

class Odometer
{
private:
	int currentMileage;
	FuelGauge *fuelG;
public:
	Odometer(int miles,FuelGauge *f){

    currentMileage = miles;
	fuelG= f;
  }
	
int getCurrentMileage(){
	return currentMileage;
}
void incrementcurrentMileage(){

        if(currentMileage < 999999 )
           currentMileage++;
		 if (currentMileage == 999999)
			 currentMileage = 0;
}
void decrementcurrentMileage(){
	 if (currentMileage > 24 )
		 currentMileage--;
	
	(*fuelG).decrementFuelTank();
	 
}
	
	 };
#include <iostream>  
#include <cstdlib>  
#include <string>
#include "FuelGauge.h"
#include "Odometer.h"
using namespace std; 

int main()
{
	
		FuelGauge fuelG(15);

        Odometer odm(0,&fuelG);

 

		
      
		for(int i=0; i<15; i++){
			fuelG.incrementFuelTank();
       
		}
 

       while (fuelG.getCurrentAmountOfFuel() > 0) 
	   {
 
			odm.incrementcurrentMileage();
	
			cout<<"Mileage: "<<odm.getCurrentMileage()<<endl;
		
	

         cout<<"Fuel level"<< fuelG.getCurrentAmountOfFuel()<<" gallons"<<endl;
			
		}
	   return 0;
	    cin.get();
}
 
Last edited on
closed account (DSLq5Di1)
                Could      you               please           fix 
the                              formatting?
         because        it's                 a           little
    difficult                      to          follow..


1
2
3
4
5
6
7
8
FuelGauge fuelG(15);

//***** what does this do that the constructor hasn't already done??
for(int i=0; i<15; i++)
{
        fuelG.incrementFuelTank();
}
//****************************************************************** 

As ResidentBiscuit pointed out,
1
2
3
4
5
6
while (fuelG.getCurrentAmountOfFuel() > 0)  // current amount of fuel never changes, always true
{
        odm.incrementcurrentMileage(); // doesn't affect the current amount of fuel
        cout<<"Mileage: "<<odm.getCurrentMileage()<<endl; // doesn't affect the current amount of fuel
        cout<<"Fuel level"<< fuelG.getCurrentAmountOfFuel()<<" gallons"<<endl; // doesn't affect the current amount of fuel
}
Topic archived. No new replies allowed.