Not sure whats wrong

I may be derping, and yes i know this is not the most efficient way to write this program but it has to be done this way as requested, anyway basically the user inputs hours and it gets converted to days then outputs how many days it is + left over hours.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int main(){
int days,hours,x,y;
x = 0;days = 0;hours = 0;y = 0;
cout << "Please enter the amount of hours you want to calculate ";
cin >> hours;
if (x < 1){
if(y < 9999 || hours > 24){
		days = days + 1;
		hours = hours - 24;
		y++;
	}
}
cout << "Theyre are " << days << " Days and " << hours << " Hours.";
x++;
system("Pause");
}


basically it just runs through the if 9999 times until it reaches under 24 hours but the problem is that it is only running through it once and example if i enter 49 hours it will say 1 day and 25 hours because it wont go through the if multiple times. I am assuming this is a very easy fix and i am missing something but any help would be greatly appreciated.
I will give you a special equation:
1
2
3
4
5
6
7
8
9
10
11
int inputInHours, days, hours;

inputInHours = 67; // You should change this to get it from the user.

days = inputInHours / 24; // Will ~magically~ round down because that's how ints work.

hours = inputInHours % 24; // The remainder after division.  Oh hey look it's the leftover hours.

cout << inputInHours << " hours is equal to " << days << " days and " << hours << " hours." << endl;

return 0;


If this is insufficient for your what you need, well, good luck.
Last edited on
Topic archived. No new replies allowed.