Cannot convert char to double?

Could anybody tell me what's wrong with this problem. I'am an absolute beginner so don't assume anything? It's saying in the compiller that it cannot convert char to double...
/* Halving 'n'*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main ()
{
double n, r;
char szInput [256];
printf("Enter the value of n: ");
gets(szInput);
n = atof(szInput);
r = szInput/2.0;
printf("Half of n is %d\n", r);
return 0;
}

Much appreciated for any help on the matter!

John
szInput is a character array (string).

You can't divide a string by 2.0.
r = szInput/2.0;
r is a double, szInput a C string. What you want to do is r = n/2
szInput/2.0 needs to convert szInput to a double to do the division. I think you meant to divide 'n' by two, not szInput?

EDIT: zomg triple response!
Last edited on
Lol! I had a long day to be honest, and I can't believe I didn't spot this.

Either way a big thanks for the quick replies!
Topic archived. No new replies allowed.