dayType

well our dr. gave us this home work annnd i have a problem in calculating the days
soo here's the Q and how i solved it and please tell what's wrong.
-------------------------------------------

#include<iostream>
#include<string>
using namespace std;

class dayType
{

public:
void setDay(string);
void printDay() const;
//void returnDay();
string returnNextDay(string&);
string returnPreviousDay(string&);
void calDay(string);
dayType();

private:
string day;
};//dayType
void main()
{
string nxt;
string pre;
dayType someDay;
string yourDay;
cout<<"Please enter a day"<<endl;
cin>>yourDay;
someDay.setDay(yourDay);
someDay.printDay();
//someDay.returnDay();
nxt= someDay.returnNextDay(yourDay);
cout<<"Tomorrow is: "<<nxt<<endl;
pre= someDay.returnPreviousDay(yourDay);
cout<<"Yesterday was: "<<pre<<endl;
someDay.calDay(yourDay);

}//main

void dayType::setDay(string d)
{
if(d=="sun"||d=="sunday")
day= "Sunday";
else if(d=="mon"|d=="monday")
day= "Monday";
else if(d=="tue"|d=="tuesday")
day= "Tuesday";
else if(d=="wed"|d=="wednesday")
day= "Wednesday";
else if(d=="thu"|d=="Thursday")
day= "Thursday";
else if(d=="fri"|d=="friday")
day= "Friday";
else if(d=="sat"|d=="saturday")
day= "Saturday";
else
cout<<"Something is wrong with the input."
<<endl
<<"Please check your input";

}//setDay()
void dayType::printDay()const
{
cout<<"Day is: " <<day<<endl;
}
//void dayType::returnDay()
//{
//
//}
string dayType::returnNextDay(string& d)
{
string n;
if(d=="sun"||d=="sunday")
{ n="Monday";
return n;
}
else if(d=="mon"||d=="monday")
{
n="Tuesday";
return n;
}
else if(d=="tue"||d=="tuesday")
{
n="Wednesday";
return n;
}
else if(d=="wed"||d=="wednesday")
{
n="Thursday";
return n;
}
else if(d=="thu"|d=="Thursday")
{
n="Friday";
return n;
}
else if(d=="fri"||d=="friday")
{
n="Saturday";
return n;
}
else if(d=="sat"||d=="saturday")
{
n="Sunday";
return n;
}
else
cout<<"Something is wrong with the input."
<<endl
<<"Please check your input";

}
string dayType::returnPreviousDay(string& d)
{
string p;
if(d=="sun"||d=="sunday")
{ p="Saturday";
return p;
}
else if(d=="mon"||d=="monday")
{
p="Sunday";
return p;
}
else if(d=="tue"||d=="tuesday")
{
p="Monday";
return p;
}
else if(d=="wed"||d=="wednesday")
{
p="Tuesday";
return p;
}
else if(d=="thu"||d=="Thursday")
{
p="Wednesday";
return p;
}
else if(d=="fri"||d=="friday")
{
p="Thursday";
return p;
}
else if(d=="sat"||d=="saturday")
{
p="Friday";
return p;
}
else
cout<<"Something is wrong with the input."
<<endl
<<"Please check your input";
}
void dayType::calDay(string f)

{ string daysOfWeek[7]={"sunday", "monday","tuesday","wednesday","thursday","friday","saturday"};
string currentDay;
string decide;
cout<<"If you want to add days, enter 1"<<endl
<<"If you want to subtract days, enter 2"<<endl;
cin>>decide;
if(decide=="1")
{
int add;
cout<<"Enter number of days you want to add"<<endl;
cin>>add;
int Dd;

if(f=="sun"||f=="sunday")
Dd=0;
else if(f=="mon"||f=="monday")
Dd=1;
else if(f=="tue"||f=="tuesday")
Dd=2;
else if(f=="wed"||f=="wednesday")
Dd=3;
else if(f=="thu"||f=="thursday")
Dd=4;
else if(f=="fri"||f=="friday")
Dd=5;
else if(f=="sat"||f=="saturday")
Dd=6;
else cout<<"Check your input";

for(int counter=0;counter<add;counter++)
{ if(Dd=6)
{
currentDay=daysOfWeek[0];

}
else
{Dd++;
currentDay=daysOfWeek[Dd];
}
}
cout<<"After adding "<<add<<" days"<<endl
<<"The day is: "<<currentDay<<endl;
}

else if (decide=="2"){}
else cout<<"Check your input";
}
dayType::dayType()
{ day="";
}
btw here's the Q
Design and implement a class dayType that implements the day of the
week in a program. The class dayType should store the day, such as Sun
for Sunday. The program should be able to perform the following operations
on an object of type dayType:
a. Set the day.
b. Print the day.
c. Return the day.
d. Return the next day.
e. Return the previous day.
f. Calculate and return the day by adding certain days to the current day.
For example, if the current day is Monday and we add 4 days, the day to
be returned is Friday. Similarly, if today is Tuesday and we add 13 days,
the day to be returned is Monday.
g. Add the appropriate constructors.
Hello,

Rather than using many if() conditionals, I would use a switch() statement, these are found in the documentation. :)

This is my first post, by the way.
well i thought about that, but first i want to make sure that everything is right then i'll change the if statements and thing like this.
my problem is that the calculator is always giving me "Sunday" even if i wanted to add just one day!
this home work should be done tonight :/
Topic archived. No new replies allowed.