Can anyone help me tweek my code. This program is supposed to get the day number 1 through 365 from the user and display the corresponding month and day. I'm getting so many errors I don't know how to start or really decipher the error in C++. Here is my code. Any pointers would be greatly appreciated.
Here is the class.

//This is the Class for my Day Converter program
#ifndef DayConverter_H
#define DayConverter_H
#include <iostream>
#include <string>


Class DayConverter
{
private:
	int day;

public:
	static const int EndOfMonth[];
	static const string Month[];
	void print();
	void setday(int d)
	{day = d}
};

void DayConverter::print()
{
	int month = 0;

//Do the math for gettig month info
While(EndOfMonth(month)< day);	
	month = (month+1) % 12;

//Display the month and day 
if(month == 0)
cout<< "January" << day;

else
{ 
	cout<< DayConverter::Month(month)<<" "
		<<day - DayConverter::EndOfMonth[month-1];
}

};

#endif

And here is the .cpp file

// This is my Day Convert Program.
//It is supposed to convert the day of the year
// to the corresponding month and day.

#include <iostream>
#include <string>
#include "DayConverter.h"
using namespace std;


const string DayConverter::Month[] = {"Janurary", "February","March",
"April","May","June","July","August","Setpember","October","November","December"};

const int DayConverter::EndOfMonth[] = {31,59,90,120,151,181,212,243,273,304,
334,365};


int main()
{
	DayConverter TI;
	int day;

//Explain what this program will do
	cout<< " This progam will take the day of the year from you."<<endl;
	cout<< " and display the corresponding month and day."<<endl;

//Get the day number from the user
	cout<< " Please enter the number of the day you would like to see: ";
	cin>> day;

	if(day <= 0 || day > 365)
	{
		cout<< " The number you enter isn't between 1 and 365." <<endl;
		exit(1);
	}

	TI.setDay(day);
	TI.print();
	cout<< endl;
	return 0;
}

Recommended Answers

All 8 Replies

Can anyone help me tweek my code. This program is supposed to get the day number 1 through 365 from the user and display the corresponding month and day. I'm getting so many errors I don't know how to start or really decipher the error in C++.

Gee, my psychic powers aren't working well today. I cannot read the errors from your screen nor mind. Sorry.

Mr. Walt there are 24 different errors how would you like me to list them. I get the feeling you are getting upset with me. I'm very sorry if I'm trying you patience or something. I just don't have a good grip on this programming thing as I'm took my first class online last term, which was November. I've never tried or been interested in writing programs before nor do I do it between classes. So I haven't seen very much code before. All I'm asking for is guidance or tips to things I should do to get better.

He's not upset, believe me. He's a mod, he's enforcing the forum rules. We can't help if you just say "I'm getting lots of errors", it's simply not possible without a starting point. You need to tell us what the errors are.

Have you done a Site Search? Have you looked at this thread? It's a very similar question.

You have a ton of easily resolvable errors in your class.
1. class and while must be lowercase ( you have them starting with a capital letter)
2. You're missing semicolons after

void setday(int d)	
{day = d}

and I'm not sure what you are trying to accomplish with those curly braces.
3. You are trying to set the integer variable 'day' to a non integer value 'd'. You must have 'd' declared as an integer as well and you'll want to give it a value.
4. It looks like your trying to use array values in the function. You need to use square brackets [] not parentheses.

Start with these problems and try again. Good luck. :)

Mr. Walt there are 24 different errors how would you like me to list them.

Yes. It's usually just a simple copy-and-paste that takes mere seconds.

main.cpp
In file included from main.cpp:7:
DayConverter.h:8: error: `Class' does not name a type
DayConverter.h:19: error: extra `;'
DayConverter.h:21: error: `DayConverter' has not been declared
DayConverter.h: In function `void print()':
DayConverter.h:26: error: `EndOfMonth' was not declared in this scope
DayConverter.h:26: error: `day' was not declared in this scope
DayConverter.h:26: error: `While' was not declared in this scope
DayConverter.h:31: error: `cout' was not declared in this scope
DayConverter.h:31: warning: unused variable 'cout'
DayConverter.h:35: error: `cout' was not declared in this scope
DayConverter.h:35: error: `DayConverter' has not been declared
DayConverter.h:35: error: `Month' was not declared in this scope
DayConverter.h:36: error: `DayConverter' has not been declared
DayConverter.h:35: warning: unused variable 'cout'
DayConverter.h:35: warning: unused variable 'Month'
DayConverter.h:26: warning: unused variable 'While'
DayConverter.h: At global scope:
DayConverter.h:39: error: extra `;'
main.cpp:11: error: `DayConverter' has not been declared
main.cpp:14: error: `DayConverter' has not been declared
main.cpp: In function `int main()':
main.cpp:20: error: `DayConverter' was not declared in this scope
main.cpp:20: error: expected `;' before "TI"
main.cpp:37: error: `TI' was not declared in this scope
main.cpp:20: warning: unused variable 'DayConverter'
*** Errors occurred during this build ***

But it has the side effect of demonstrating to contributors here that indeed you are actively trying to solve your own problems in addition to asking for assistance. That is, good manners.

Starting at the top, you should note that C and C++ are case-sensitive: class is different from Class . If then rebuilt, you would find that some of the diagnostic messages are now different -- this is because some errors mask others. Now it might look like this:

In file included from main.cpp:7:
DayConverter.h:15: error: `string' does not name a type
DayConverter.h:15: error: extra semicolon
DayConverter.h: In member function `void DayConverter::print()':
DayConverter.h:26: error: `DayConverter::EndOfMonth' cannot be used as a function
DayConverter.h:26: error: `While' was not declared in this scope
DayConverter.h:31: error: `cout' was not declared in this scope
DayConverter.h:31: warning: unused variable 'cout'
DayConverter.h:35: error: `cout' was not declared in this scope
DayConverter.h:35: error: `Month' is not a member of `DayConverter'
DayConverter.h:35: warning: unused variable 'cout'
DayConverter.h:26: warning: unused variable 'While'
DayConverter.h: At global scope:
DayConverter.h:39: error: extra `;'
main.cpp:11: error: `const std::string DayConverter::Month[]' is not a static member of `class DayConverter'
main.cpp: In function `int main()':
main.cpp:37: error: 'class DayConverter' has no member named 'setDay'
*** Errors occurred during this build ***

Again, starting at the top, we find that the compiler can't find string . Here you either need to be using std::string; or explicitly declare it like this (the other way I choose not to mention):

static const std::string Month[];

Again, the error messages may have changed a bit. Find the next error, fix it; lather, rinse, repeat until you have no more errors or warnings.

Raise questions about specific error messages you don't know how to fix. This way you can learn how to fix them. And in doing so, you don't turn online forums and helpful posters into really, really slow compilers (relatviely speaking). ;)

> Mr. Walt there are 24 different errors how would you like me to list them.
http://cboard.cprogramming.com/c-programming/88495-development-process.html
Start small and compile(*) often.

Whilst you're learning, you have to accept that most of the time the compiler will just spit your latest effort out.

It works like this:
= If you add only 5 lines and get a new error message, you've got a nicely contained problem you can probably figure out.
= Write hundreds of lines, you WILL get errors by the page and you're reaching for the forum post button.

If you don't understand a single error message, that's fine. We can help you understand.

But this isn't a dumping ground for a "code fix it service". We might humour you on the first post, but it's not a strategy that will work long term.

(*) this also extends to testing.
Crafting a masterpiece over several days only to find out that it crashes at the first function. As you finish a small useful bit, test it.

thank you for your responses I've got the errors down to six now. I have a little work to do but I think I'm getting it. Thanks for the tip about compiling small bits of code at a time I will help a lot.

You'll find you get alot of good advice from senior posters like Walt, Dave, and Salem. When they post, you would be well advised to read their posts very carefully.

I can't begin to tell you how much I've learned from them, and others like them, in the last 4 or 5 months.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.