Hi,
To test my skills I'm attempting to write a program to just display text on how far you have gone and the amount of gas you have as if you were driving a car. W would be the drive button. I'm getting a bunch of errors from the code that i have so far, and also, I'm not really sure how to make the number change for the amount of gas. Please help
What I would want the program to look like is:
Amount of Gas Left: [changing amount based on distance driven]
Miles Driven: [changing amount based on distance]
If you press w you go, if you release it you stop. It's basically a simple counter so far.
This is the code i have so far:
#import <Foundation/Foundation.h>
@interface car : NSObject
{
char input;
float g;
float miles;
}
-(float) calculateGas;
-(char) setC;
-(float) g;
-(float) miles:
-(char) input;
@end
@implementation car
-(float) g
{
return g;
}
-(float) miles
{
return miles;
}
-(char) input
{
return input;
}
-(char) setC;
{
char c;
input = c;
scanf ("%c", c);
return c;
}
-(float) calculateGas;
{
char c;
if (g != 0)
{
while (scanf ("%c", &c) = 'w')
{
++miles;
g -= (miles * .03);
}
}
else
{
NSLog (@"Sorry you don't have any more gas, you're screwed...");
}
return g, miles;
}
@end
#import <Foundation/Foundation.h>
#import "carFunc.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
car *myCar = [[car alloc] init];
NSLog(@"Welcome to the car program. To drive, press w...");
[myCar setC];
//check for input
if (myCarc = 'w')
{
[myCar calculateGas];
NSLog (@"You have driven %f miles", miles);
NSLog (@"You have %f gallons of gas left", %f);
}
else
{
[Wasn't sure how to make it return to check again for input]
}
[myCar release];
[pool drain];
return 0;
}