Mar 21, 2009 at 4:08pm UTC
atof() does ASCII to float, where ASCII essentially means C-string.
The problem with your code is on the line that the compiler is complaining about.
(Hint: typecasting and typecast warnings are very often bugs in your code).
Mar 21, 2009 at 7:37pm UTC
So you're saying that what i thought to be "change this char array to a double" is actually saying "change this char array to C-string"?
I'm not gonna lie i'm confused on what I can do :S
Mar 21, 2009 at 9:23pm UTC
char array and C strings are the same thing, a double is a floating point number
*a = atof(a);
atof returns a double and you are assigning its data to a char (which is mush smaller than a double) so is likely that you will lose data in the conversion
Mar 22, 2009 at 1:39pm UTC
It have something to do with the way i'm passing it to the function though, because this program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
char ch[8] = "123345" ;
int num = 2;
cout << atof(ch) + num;
cin.get();
return 0;
}
gives out the right output of 123347
and if i change my code to just on line 24 to just cout atof(salary) then it works fine. What is wrong with my function?
Last edited on Mar 22, 2009 at 1:41pm UTC
Mar 22, 2009 at 2:18pm UTC
Hmm well the right numbers are being outputted now but the "Current Salary: " isn't.