Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

maximum value for a variable

Status
Not open for further replies.

Honkey

Technical User
Mar 28, 2004
2
0
0
US
how do i set a maximum value for a variable. say i have the number 5.70 i want to set the variable to not let the tenths and hundredths places to get past 59 if they are beyond 59 then round up from for example. 5.70 to 6.10 or 5.65 rounded to 6.05..can this be done.....i`m trying to program a pay roll for a class assignment and i need help i already have the daily hours worked, the uder inputs start and end times and the computer subtracts the start time from 12.60 (12 hours on a clock 60 mins in an hour) then subtracts that number from the end time to get hours worked in a day but sometimes the mins are over 59 so i need it to round the hours up..
thanx alot for your help i really appreciate it

Honkey
 
Here there is probably a better way to do this but I had this laying around so I thought I would give it to you ;)

Code:
using namespace std;

int main()
{
	float time = 6.70;
	
	int minutes = int(time);
	float seconds = time - float(minutes);

	if(seconds>.59)
	{
		seconds = seconds - .59;
		time = int(time);
		time++;
		time += seconds;
	}

	cout << time << endl;

	return 0;
}
 
thanx alot thats exactly what i needed to know..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top