Thanks much for such quick responses! Now bear with me as I try to interpret with my nooby brain.
First, I see my obvious line 21 and floor mistake.
Next, half of what was said had no been learned yet (adding .0f or unsigned), but I did some research to figure out what those mean.
But - trying to avoid possibly using more advanced techniques as the book states to use float (unsigned, even though it is far less messy) and using what I have, I've been trying to figure out how to use this answer:
Looks like you have integer division, which will discard the fractional part.
e.g. startHr = s/100;
both s and 100 are integers.
You could use s/100.0f to specify that 100 is of type float, not int.
Here is my modification with error:
using namespace std;
int calculations(int, int);
cout << "Please input your start time in military time(example: 8:30=2030): ";
cin >> start;
cout << "Please input your end time: ";
cin >> end;
cout << "Your elapsed time is " << calculations(start, end) << " minutes.";
int calculations(int s, int e) //calculations to determine the difference in time
float startHr, //separation of hours and minutes
startDec, //hours and minutes in decimal form
startMin, //minutes when separated from hours
startHr = s/100.0f; //calculations to separate the hour to integer form
startMin = s%100.0f; //calculations to find remainder in minutes
startDec = startMin/60.0f + startHr; //converting minutes to decimal form and adding to hours
endHr = e/100.0f; //same calculations for end time
endMin = e%100.0f;
endDec = endMin/60.0f + endHr;
return (endDec - startDec)*60.0f; //return of final calculations in decimal form multiplied by 60 to convert to minutes
I receive an error:
error: invalid operands of types ‘int’ and ‘float’ to binary ‘operator%’
endMin = e%100.0f;
(Using Netbeans btw)
I tried to just add .0f to each the s/100 and e/100 but the result was the same.
Trying to add the .0f to every other constant obviously doesn't work, why is that? How could I make that work? Is the rounding solution the only other way? (as stated by Irrelevant Elephant)