looping days

how i want to get

Enter days : 75
Equivalent to...
WEEK DAY
---- ---
10 5


here is my code (i think it broken already)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

int main()
{
	int days, weeks, b=1;

	cout<<"Enter days : ";
	cin>>days;

	cout<<"\n\nEquivalent to... "<<endl;

	cout<<"WEEK \t DAY"<<endl;
	cout<<"---- \t ---"<<endl;

	for (int i=days; i<7 ; i-=7)
	{
		b=b+1;
	}	
		
	cout<<b<<endl;

	system ("PAUSE");
	return 0;
}
why don't you just use division and modulo operation, to calculate the weeks and remaining days

example:

days = 75

75 / 7 = 10 , works since you divide integers
75 % 7 = 5 , modulo operation, returns the rest of the division

=> 75days = 10 weeks and 5 days
the reason is to apply usage of looping. but in the end, i manage to get the right code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

int main()
{
	int days, b=0;

	cout<<"Enter days : ";
	cin>>days;

	do
	{
		b=b+1;
		days-=7;
		
	}
	while (days >=7);

	cout<<"\nEquivalent to... : "<<endl<<endl;
	cout<<"\nWEEKS \t DAYS "<<endl;
	cout<<"----- \t ---- "<<endl;
	cout<<b<<"\t  "<<days<<endl;
	cout<<"\nThank you..."<<endl;

	system ("PAUSE");
	return 0;
}
Topic archived. No new replies allowed.