GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Sep-2006, 19:24
cbruckman2006 cbruckman2006 is offline
New Member
 
Join Date: Sep 2006
Posts: 2
cbruckman2006 is on a distinguished road

Day of week Functional decompostion


Ok I am doing an assignment for school. Here is what I have to do.

Use functional decomposition to write a C++ program that takes a number in the range of 0 to 6 and a second number in the range of 1 to 366 as input. The first number represents the day of the week on which the year begins, where 0 is Sunday, and so on. The second number indicates the day of the year. The program 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 by computed as follows:
(startday + day of year - 1) %7

The program should output an error message if the numbers entered are not in the required ranges. The prompt adn the error message should make it clear to the user how the numbers must be entered. Be sure to use proper formatting and appropriate comments in your code. The output should be labeled clearly and formatted neatly.

Ok I have come up with some of the code for this. The code works but I am not sure if the proper data is being output. Also I have an error message coded but I don't know if I have it right and it really isn't doing what I want it to do.

Here is my code so far:

CPP / C++ / C Code:
//************************************************
//Project:		Day of week program
//Programmer:	Chad R. Bruckman
//Date:			9/28/06
//Description:	This program outpus the name of the day
//				of the week corresponding to the day of
//				the year.
//************************************************
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

int main()



{
int integer1, integer2;	//Enters day of week and day of year.
int dayofweek;

// User inputs data by using these statments
cout<< "Enter Day of Week (Example: Sun=0,Mon=1,Tues=2,Weds=3,Thur=4,Fri=5,Sat=6): ";
cin >> integer1;	//Takes in data
if (integer1 >6)
cout << "Number must be between 1 and 6"<< endl;
else 
if (integer1 < 1)
cout << "Number must be between 1 and 6"<< endl;

cout<< "Enter Day of Year: ";
cin >> integer2;	//Takes in data
if (integer2 < 1)
cout << "The day of year must be between 1 and 366" << endl;
else 
if (integer2 > 366)
cout << "The day of year must be between 1 and 366" << endl;



dayofweek = (integer1 + integer2 - 1)%7;

// Decides which day of week has been calculated.
if (dayofweek == 0)
cout <<"The day of the week is Sunday";
else
	if (dayofweek == 1)
		cout << "The day of the week is Monday";
	else
		if
			(dayofweek ==  2)
			cout<< "The day of the week is Tuesday";
		else
			if (dayofweek ==  3)
				cout << "The day of the week is Wednesday";
			else 
				if (dayofweek == 4)
					cout << "The day of the week is Thursday";
				else
					if (dayofweek == 5)
						cout << "The day of the week is Friday";
					else 
						if (dayofweek == 6)
							cout <<"The day of the week is Saturday";
						






cin.get();
cin.get();

return 0;

}
Last edited by LuciWiz : 30-Sep-2006 at 11:05. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 30-Sep-2006, 07:18
ubergeek ubergeek is offline
Awaiting Email Confirmation
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough

Re: Day of week Functional decompostion


First, please format your code so we can read it and enclose it in [ c++ ] and [ /c++ ] (without the spaces) tags. Then, read the Guidelines. Ask yourself these questions:
1. Does the code compile?
Yes: go to #2
No: show us the code (you did that) and copy and paste the exact error messages.
2. Does the program crash?
Yes: tell us what you input, and what output up until the crash.
No: go to #3
3. What did you expect the program to do?
4. What does the program do?
5. Is there a difference between the answers to #3 and #4?
Yes: tell us the input and output, and what you don't understand about said difference.
No: well, why are you here then?
  #3  
Old 30-Sep-2006, 12:08
cbruckman2006 cbruckman2006 is offline
New Member
 
Join Date: Sep 2006
Posts: 2
cbruckman2006 is on a distinguished road

Re: Day of week Functional decompostion


Well I don't gues I will be posting here anymore because I am not too sure how much more specific I can get without drawing a picture. Smart *** comment's are not appreciated. Have a nice day. Thanks for the help in which I recieved none.
  #4  
Old 30-Sep-2006, 14:51
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,432
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Day of week Functional decompostion


So draw a picture.

It's really hard to help someone when they don't post accurate information, and in a way it can be read -- then when we ask for clarification we're the smart*** for explaining what we need to understand your problem.

You claim
Quote:
Originally Posted by cbruckman2006
The code works but I am not sure if the proper data is being output.
If you're not sure, how can we be sure? We don't know what your program is supposed to do. When writing a program you have to have test data you can test with. You can't leave it up to someone else to come up with the input data and expext them to know if the program works.

Quote:
Originally Posted by cbruckman2006
Also I have an error message coded but I don't know if I have it right and it really isn't doing what I want it to do.
If it isn't doing what you want, it isn't right. Unless you don't know what it's supposed to do. Again, how are we supposed to know? If it's not doing what you want, what is it that tells you so? Do you know what it is suposed to do? Without that information what can we possibly say?

[smart*** comment]
"Hi mechanic, my car starts, and it runs, but I don't think it runs right. And when I turn the wheel, I'm not sure if it's doing the right thing..." With this info, could you fix the car?
[/smart*** comment]
That's a smart*** comment...
__________________

Definition: Politics
Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
 
 

Recent GIDBlogEnable Compression for SSH by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
NFL Preview, Regular Season Week 2 john1981cr Sports Forum 0 13-Sep-2006 11:41
Figuring out the day of the week Darth Predator C++ Forum 13 31-Jul-2006 17:20
Return month by providing work week shinyhui C++ Forum 7 22-Feb-2005 07:23

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:02.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.