Read your code. Each and every line and understand exactly what it does.
Then write a flowchart with that, knowing what it does.
Then insert your check where appropriate in the flowchart.
Then translate it to code.
It will do you wonders.
Printable View
Read your code. Each and every line and understand exactly what it does.
Then write a flowchart with that, knowing what it does.
Then insert your check where appropriate in the flowchart.
Then translate it to code.
It will do you wonders.
varts what can i say you are a legend
so the real devils are { and }
thx for the help mats and elysia
since im on it
im just wondering how do i convert year outputs into words?
does it involve with enumerations cause if it does dont i have to create some sort of dictionary?
any pointers plz?
You will need some sort of translation of number to string - if you want to call that a dictionary, then that's probably closer than an "enumeration".
--
Mats
translation of number to string....
right....
are there websites or tutorials that can tell me about that cause i have no idea how to start at all
thx mats
P.s: does it invole #include <stdlib.h>??? there's only one setence from this website (http://www.cs.cf.ac.uk/Dave/C/node16...00000000000000)
which does not really help
Don't worry about including headers.
Worry about what functions to use, and when you use those functions, include appropriate header.
haha i just need a header in case my teacher saw this thread and said i plagiaries
You definitely don't need stdlib.h for this particular task:
This solves PART of your problem - now you have to find the rest of the solution.Code:#include <stdio.h>
int main()
{
char *numbers[] = { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
int n;
printf("Enter a number:");
fflush(stdout);
scanf("%d", &n);
printf("Last digit of number is %s", numbers[n % 10]);
return 0;
}
--
Mats
Including a header without using is bad. Especially if you just want someone to "see" that header.
thx for the sample mat
can someone explain what is
fflush(stdout);?
and
char *numbers[] ?
fflush(stdout) -> flushes output buffer, makes sure the user sees the "Enter a number:" text.
char* numbers[] (as I like to type it) clearly shows that it's an array of pointers (type) and [] means that the dimensions are undefined (the compiler will determine this depending on what you initialize it with).
But this should really be const char*...
Now that he's got the answer, I'd like to post my version
I've got the functionCode:void processInput(int year, int month)
{
int leap = ( (year%4 == 0 && year%100 != 0) || year%400 == 0 )? 1:0;
// one of the ways to check if a given year is leap
int monthDays[] = {31,28+leap,31,30,31,30,31,31,30,31,30,31};
// adjust num of days in February accordingly
const char *monthStr[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
// string constants for each month
char yearStr[40];
// string variable for year in words
getYearInWords(yearStr, year);
printf("year %d (%s) has %d days\n", year, yearStr, (365+leap));
printf("month %d (%s) has %d days\n", month, monthStr[month-1], monthDays[month-1]);
}
ready but didn't post it coz i don't want to stop him learning.Code:getYearInWords(yearStr, year);
Anyway, this function just uses logic as explained earlier by matsp
cheers
maverix
But if you want something fancy, you can do this ;)
Code:int leap = !!( (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) );
You may be correct...
I didn't really think of it.