Heya guys :)
Currently coding a converter for days into weeks and days.
It all works fine, and allows me to convert the amount of days I want into weeks and days, but it isn't perfect.
For an amount of days such as 8, it is 1 week and 1 day.
For an amount of days such as 9, it is 1 week and 2 days.
dayand
days are different words.
So when a number of days is entered which ends up being however many weeks and 1 DAY, I want it to display that it is 1 DAY, not DAYS.
And when a number of days is entered which ends up being however many weeks and more than 1 day, I want it to display that it is however many DAYS, not day.
So how do I do this?
This is my current working 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 29 30 31
|
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main (void)
{
//Declare variables
int days1,days2,weeks;
//Heading
printf("This program allows you to input a number of days and will convert it to weeks and days\n\n");
//Input number of days
printf("Input a number of days: ");
scanf("%d",&days1);
//Calculate number of weeks
weeks=days1/7;
//Calculate number of days remaining
days2=days1%7;
//Output result
printf("%d",days1);
printf(" days equals: \n");
printf("%d",weeks);
printf(" weeks and ");
printf("%d",days2);
printf(" days");
getch();
}
|
I know this could probably be shortened a lot, but I'm not interested in that. I just want to be able to create an if, else statement which allows the program to display DAY or DAYS correctly, rather than DAYS all the time.
This probably does't make much sense.. I'm completely shattered, and could probably word it a lot better if I was more awake lol.
Cheers for any help,
Liam