Feb 17, 2015 at 5:08pm UTC
Hi there,
i'm having hard time fixing my code.
It gives me scanf C4996 warning, but i don't know what i did wrong!
The program should calculate the miles driven using main function and then calculate the miles per gallon using user defined function (fuel).
many thanks in advance.
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
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define value1 gallon_used
#define value2 starting_miles
#define value3 ending_miles
double Fuel(int value1, int value2, int value3);
void main()
{
int value1, value2, value3;
int miles_driven = value3 - value1;
printf("Enter the gallon used:" );
scanf("%d" , &value1);
printf("Enter the starting miles:" );
scanf("%d" , &value2);
printf("Enter the ending miles:" );
scanf("%d" , &value3);
print("Results:" );
printf("The miles driven are %Lf\n" , miles_driven);
printf("The miles per gallon was: %Lf\n" , Fuel(value1, value2, value3));
printf("Press any key to continue" );
getch();
}
double Fuel(int value1, int value2, int value3)
{
return ((value3 - value2)/(value1));
}
Last edited on Feb 17, 2015 at 5:09pm UTC
Feb 17, 2015 at 5:13pm UTC
Last edited on Feb 17, 2015 at 5:14pm UTC
Feb 17, 2015 at 5:28pm UTC
Thanks for the help.
But the main error was missing f after print for result.
Feb 17, 2015 at 6:32pm UTC
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
#include <stdio.h>
#include <conio.h>
#include <math.h>
using namespace std;
#define value1 gallon_used
#define value2 starting_miles
#define value3 ending_miles
double Fuel(double value1, double value2, double value3);
double Fuel(double value1, double value2, double value3)
{
return ((value3 - value2) / (value1));
}
int main()
{
double value1 = 0, value2 = 0, value3 = 0;
double milesdriven = 0;
printf("Enter the gallon used:" );
scanf_s("%lf" , &value1);
printf("Enter the starting miles:" );
scanf_s("%lf" , &value2);
printf("Enter the ending miles:" );
scanf_s("%lf" , &value3);
printf("Results:\n" );
milesdriven = value3 - value2;
printf("The miles driven are %lf\n" , milesdriven);
printf("The miles per gallon was: %.4lf\n" , Fuel(value1, value2, value3));
printf("Press any key to continue" );
getch();
return 0;
}
You tell it milesDriven = value3 - value2; before you even input values to value3 and value2.
Last edited on Feb 17, 2015 at 6:39pm UTC
Feb 17, 2015 at 10:59pm UTC
Why'd you all write it in C ? This is a website about C++ .
Last edited on Feb 17, 2015 at 11:00pm UTC