For an assignment for class i wrote this code right but the only problem i have is that i can't get the right value that assignment wants which is distance so far: 0 meters
distance so far: 1000 meters
distance so far: 0 meters
distance so far: 0 meters
distance so far: 2000 meters
distance so far: 0 meters
You can't start pedaling before you get on first!
You can't getOff before you getOn first!
ill post the code

#include <iostream>
using namespace std;
class Bike
{
public:
   int getOn()
   {return place;}
    int pedal(int getDistance)
    {return distance;}
    int getOff()
    {return place;}
    int getDistance()
    {return 0;}


private:
double distance;
int place;
int my_Distance;
bool my_someoneIsOn;
};

int main()
{

Bike( );
void getOn();
void pedal( int distance );
void getOff();

int getDistance();
int my_Distance;
bool my_someoneIsOn;
Bike b;
cout << "distance so far: ";
cout << b.getDistance( );
cout << endl;
b.getOn( );
b.pedal( 1000 );
cout << "distance so far: ";
cout << b.getDistance( );
cout << endl;
b.getOff( );
cout << "distance so far: ";
cout << b.getDistance( );
cout << endl;
b.getOn( );
cout << "distance so far: ";
cout << b.getDistance( );
cout << endl;
b.pedal( 2000 );
cout << "distance so far: ";
cout << b.getDistance( );
cout << endl;
b.getOff( );
cout << "distance so far: ";
cout << b.getDistance( );
cout << endl;
b.pedal( 500 );
b.getOff( ); 
return 0;
}

Recommended Answers

All 2 Replies

delete lines 26-31 because they are do-nothing lines. They are not calling any functions within class Bike, but just predeclaring global functions that your program never uses.

The logic of your Bike class is completely wrong.

When you pedal x amount of meters, you should add that to distance.

Then when you want to get the distance travelled so far, you're simply return 0. Return 'distance' instead.

You also have to use boolean variables to check if your on the bike and if your off it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.