11 Replies - 2689 Views - Last Post: 18 October 2006 - 05:51 AM Rate Topic: -----

#1 ersports86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-October 06

Day of Week Determination

Posted 18 October 2006 - 04:02 AM

I have to write a program using functional decomposition that takes a # in the range of 0 to 6 and a second number in the range of 1 to 366 as input. The 1st # represents the day of the week on which the year begins, where 0 is Sunday, and so on. The 2nd number indicates the day of the year. The program then outputs the name of the day of the week corresponding to the day of the year. The number of the day of the week can be computed as follows: (start day + day of year - 1) % 7. I have attached what I've got so far. If anyone could tell e what I'm missing or doing wrong it would be greatly appreciated.


By the way here is my error messages:
1>------ Build started: Project: Test, Configuration: Debug Win32 ------
1>Compiling...
1>Main.cpp
1>c:\documents and settings\josh\my documents\visual studio 2005\projects\a\a\main.cpp(57) : error C2562: 'main' : 'void' function returning a value
1> c:\documents and settings\josh\my documents\visual studio 2005\projects\a\a\main.cpp(14) : see declaration of 'main'
1>Build log was saved at "file://c:\Documents and Settings\Josh\My Documents\Visual Studio 2005\Projects\a\a\Debug\BuildLog.htm"
1>Test - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Attached File(s)


This post has been edited by ersports86: 18 October 2006 - 04:34 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Day of Week Determination

#2 BitByte  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 194
  • Joined: 09-August 06

Re: Day of Week Determination

Posted 18 October 2006 - 04:42 AM

View Postersports86, on 18 Oct, 2006 - 04:02 AM, said:

I have to write a program using functional decomposition that takes a # in the range of 0 to 6 and a second number in the range of 1 to 366 as input. The 1st # represents the day of the week on which the year begins, where 0 is Sunday, and so on. The 2nd number indicates the day of the year. The program then outputs the name of the day of the week corresponding to the day of the year. The number of the day of the week can be computed as follows: (start day + day of year - 1) % 7. I have attached what I've got so far. If anyone could tell e what I'm missing or doing wrong it would be greatly appreciated.


Hi ersports86
well first you have two variables with spaces in them,

int start day;
int day of year;


the compiler will see 'day' and 'of year' as errors. If you want to use more than one word there cannot be any spaces use:

int start_day or int startDay
same goes for day of year -> dayOfYear or day_of_year

Now the variable start day, it's uninitialized and never gets used for input. Which could cause you program to crash. You say you need two two numbers but you only ask for a value for day of year. Where is the value for start day? Fix these small errors and everything should be ok :)

Forget to mention, it's cmath not math.

This post has been edited by BitByte: 18 October 2006 - 04:49 AM

Was This Post Helpful? 0
  • +
  • -

#3 ersports86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-October 06

Re: Day of Week Determination

Posted 18 October 2006 - 04:55 AM

I did that and it still don't work

Attached File(s)


This post has been edited by ersports86: 18 October 2006 - 04:57 AM

Was This Post Helpful? 0
  • +
  • -

#4 BitByte  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 194
  • Joined: 09-August 06

Re: Day of Week Determination

Posted 18 October 2006 - 05:02 AM

remainder = (StartDay + DayOfYear - 1) % 7;


Compilers are case sensitive, look at the remainder variable, here you use 'remainder', all your others are ' Remainder' with a capital R. These are considered as two seperate variables.
Was This Post Helpful? 0
  • +
  • -

#5 ersports86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-October 06

Re: Day of Week Determination

Posted 18 October 2006 - 05:05 AM

Still not working. I don't know what I'm doing wrong.
Was This Post Helpful? 0
  • +
  • -

#6 ersports86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-October 06

Re: Day of Week Determination

Posted 18 October 2006 - 05:16 AM

Do you have any other ideas why it's not working?
Was This Post Helpful? 0
  • +
  • -

#7 BitByte  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 194
  • Joined: 09-August 06

Re: Day of Week Determination

Posted 18 October 2006 - 05:17 AM

Remainder = ((start day + day of year - 1) % 7);

The brackets.
Was This Post Helpful? 0
  • +
  • -

#8 ersports86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-October 06

Re: Day of Week Determination

Posted 18 October 2006 - 05:30 AM

It's compiling and building but its not doing what it's supposed to do when I run the executable. See what you think.
Was This Post Helpful? 0
  • +
  • -

#9 BitByte  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 194
  • Joined: 09-August 06

Re: Day of Week Determination

Posted 18 October 2006 - 05:42 AM

If i put it 40 and 5, 40 + 5 - 1 % 7 = 2 which equals Tuesday. Going by your program that is correct. What output are you expecting? Could you explain a bit more on what you expect the outcome to be?

0 = Sunday
1 = Monday
2 = Tuesday <-- Here 2 is tuesday

This post has been edited by BitByte: 18 October 2006 - 05:48 AM

Was This Post Helpful? 0
  • +
  • -

#10 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: Day of Week Determination

Posted 18 October 2006 - 05:43 AM

View Postersports86, on 18 Oct, 2006 - 05:05 AM, said:

Still not working. I don't know what I'm doing wrong.

I have a suggestion...
C/C++ is usually case sensitive unless you turn that feature off,,,,

int Remainder is not the same as remainder = ...
Was This Post Helpful? 0
  • +
  • -

#11 ersports86  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 18-October 06

Re: Day of Week Determination

Posted 18 October 2006 - 05:49 AM

I figured it out. Thank you so much. I couldn't have done it without you. Thank You!!!
Was This Post Helpful? 0
  • +
  • -

#12 BitByte  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 194
  • Joined: 09-August 06

Re: Day of Week Determination

Posted 18 October 2006 - 05:51 AM

View Postersports86, on 18 Oct, 2006 - 05:49 AM, said:

I figured it out. Thank you so much. I couldn't have done it without you. Thank You!!!


No probelm at all, just glad you finished it :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1