I decided to try learning to code again for the upteenth time and I'm currently trying to refresh my memory by creating a banking program where a user can withdraw and deposit money. I'm trying to create a function that checks if a user input is a number that goes beyond the cent value and then prompts them to re-enter if so. Unfortunately, when I run the program it will always tell me that there is an invalid entry.
#include <iostream>
#include <cmath>
using namespace std;
// The following is the function spoken of.
double yagoof(double c) {
double cent = .01;
double rem = fmod(c, cent);
cout << rem << endl;
while (rem != 0) {
cout << "Invalid entry. Please enter a number rounded to the nearest cent.\n\n";
cin >> c;
rem = fmod(c, cent);
cout << rem << endl;
}
return c;
}
int main(){
...
}
I added the "cout << rem..."s after getting frustrated and wanting to see if I can figure something out. It will always tell me that rem is '.01'.
I guess I'm curious as to what I did wrong here. I've reviewed it in my head a few times and I'm not getting anywhere.
I can post the whole code if needed, I just didn't do it now because it has a bunch of notes.