Write your question here.
Can anyone help evaluate any errors with the code I wrote?
The program is suppose to calculate the user's money into the minimum number of U.S. coins.
When I began to build the solution it showed 5 uninitialized local variables and conversion from double to int "possible loss of data". Don't really know how to address and resolve the issue. Any suggestions?
A lot of questions for this problem have been asked recently on the forum - try using the search feature or google search. If you still need help then let us know.
Instead of fiddling with floating point IO, I simply read the total into a string and then removed the decimal point character and finished by converting the string directly into an int. Heres the function, it took like 2 minutes to write and its important to know how to convert strings.
1 2 3 4 5 6 7 8 9 10 11 12
int strDecToInt(string s)
{
for (int i = 0; i < s.size(); i++)
if (s[i] == '.')
{
s = s.substr(0, i) + s.substr(i+1);
break;
}
stringstream ss(s);
int n; ss >> n;
return n;
}
I trust that you can work through the above code and extend it into your program; ask away if you have any questions. It might be too complex for what you need, but I find it works pretty well by avoiding IO issues and type conversions.