OKay my problem is this: Im trying to write a program that will accept user input for the day of the week (eg. Wednesday) and an "n" number of days from now between 1000 and 10000. My program is then supposed to output the day of the week after "n" days. Now... i am using the modulus operator for this dividing by 7. I am fine at getting the input and doing that simple calculation but my problem is how do i get it to output which day it is? I know i should assign each day a number from 0-6 or 1-7. But how do i get it to actually figure out which day it is? Do i use if statements? I do not know how to set up my logic for the output. Can i do this by using strcmp() and if so how? Thanks for any help.
ATTENTION C PROGRAMMERS - i have an easy program that im having some trouble with and need some direction?
You would set up an array of strings (this code isn't showing you how to do it; just what the values should be set to).
daysofweek[0] = "Sunday"
.
.
daysofweek[6] = "Saturday"
The user does have to start the process by entering the day of the week, which you must identify If they enter the string, you would have to convert it to the right format (uppercase followed by lowercase) and then use 'strcmp' to see which of the array elements it matched. The index of that becomes the starting point. Alternatively, you can just print up a menu and tell them to enter the number corresponding to the day of week - simple and accurate!
Then, add the number they entered, and use the modulus operator to finish up with a number between 0 and 6.
The day of the week is then just the array element at that index value.
eg if they enter Wednesday (3) and 12, that adds to 15, leaving 1 after the modulo 7 operation. Therefore the answer is Monday. Which agrees with common sense.
Reply:Make an array of strings and store all the days of the week into it
[edit]
@lilxkid24
I don't think he need AA code
[edit2]
does this have to be in C? Using C++ would make life a lot easier.
Reply:You should consider using 0-6 to represent your days, and in an array. That way, you can simply do the calculation, and use the result as the basis of the "index" of the appropriate day (e.g. you'll most likely get a value of 0-6 after the calculation, based on that, just use that "result" as the index of your day representation).
If you will use 1-7, you'll just have to add 1 to the result. As arrays are 0-based index.
Reply:Hi Jeniffer Lopez,
Processing:
suppose day = Wednesday = 3 and "n" = 3000
step1: add day and n =%26gt; 3 + 3000 = 3003
step 2: (result of above)modulo7 =%26gt; 3003%7 = 0
Output:
have a enumerator like this:
enum {MON = 0, TUE, WED, THU, FRI, SAT, SUN};
assuming you stored the modulus result in a variable called "result_day", do this
switch(result_day)
{
case MON:
printf("day is Monday\n");
break;
case TUE:
printf("day is Monday\n");
break;
/* and so on till case SUN:*/
}
good luck!
Reply:[Enable]
Alloc(guard,64)
Label(ret)
00698419:
mov [ebp-46],ebx
0069840E:
je 006983f7
00698413:
jmp guard
nop
ret:
guard:
mov [ebp+2c],00
mov [ebp+4c],00
jmp ret
[Disable]
00698419:
mov [ebp-48],ebx
0069840E:
jne 006983f7
00698413:
mov [ebp-2c],ebx
mov [ebp-4c],ebx
DeAlloc(guard)
this help?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment