I have two programs here I cannot seem to get any return value and I have no idea why, everything I'm doing is just like my book says and I cannot get it working.

The parts commented out are the other ways I was trying to make this work, somethings wrong because they're both not working

This one convert miles to kilometer as many times and increment value you select

``````int main(int argc, char *argv[])
{
void conversions(double, int, double);  //prototypes
double milesToKm(double);

double miles = 0;
int conv = 0;
double inc = 0;

printf("Enter the miles:\n");
scanf("%d", &miles);
printf("Enter the number of times you want to be converted:\n");
scanf("%d", &conv);
printf("Enter the increment between conversions:\n");
scanf("%d", &inc);

conversions(miles, conv, inc);

system("PAUSE");
return 0;
}
void conversions( double miles, int conv, double inc)
{
int i;
double km;
printf("MILES   KILOMETERS\n");
printf("-----   ----------\n");
for (i = 0; i < conv; i++){
km = milesToKm(miles);
printf("%3.2d    %6.2d\n", miles, km);
//         printf("%3.2d    %6.2d\n", miles, milesToKm(miles));
miles += inc;
}
}
double milesToKm(double miles)
{
double km;
km = miles * 1.6093;
//    return miles * 1.6093;
return (km);
}``````

This one is to calculate win percentage

``````int main(int argc, char *argv[])
{

double winPercent(double, double);
double win, loss;
double perWin;

printf("Enter the number of wins:\n");
scanf("%d", &win);
printf("Enter the number of losses:\n");
scanf("%d", &loss);

perWin = winPercent(win, loss);

printf("The win percentage is: \n", perWin);

system("PAUSE");
return 0;
}
double winPercent(double win, double loss)
{
double percWin;
percWin = (100 * win / (win + loss));
return (percWin);
}``````

Any help is appreciated, I cannot see anything wrong is my code from what has been taught.

Hello!

printf("Enter the number of wins:\n");
scanf("%d", &win);
printf("Enter the number of losses:\n");
scanf("%d", &loss);

given that you have defined win and loss as

``double``

You must use scanf with a different syntax, refer to:
http://www.cplusplus.com/reference/clibrary/cstdio/scanf/

## All 2 Replies

Hello!

printf("Enter the number of wins:\n");
scanf("%d", &win);
printf("Enter the number of losses:\n");
scanf("%d", &loss);

given that you have defined win and loss as

``double``

You must use scanf with a different syntax, refer to:
http://www.cplusplus.com/reference/clibrary/cstdio/scanf/
But in short:

``scanf("%lf",&win);``

is used in the case of doubles.

``scanf("%d", &win);``

is used when win is an integer.
Moreover...

``printf("The win percentage is: \n", perWin);``

Here you have messed up the syntax yet again, it should be:

``printf("The win percentage is: %lf\n", perWin);``

I suggest you read the following:
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
Hope this helps, good luck.

thanks

Be a part of the DaniWeb community

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