This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
3
week day program help
Post Flair (click to view more posts with a particular flair)
Post Body
Hey so its a simple program it is an array of the whole week. and they’re is 2 functions really that’s next day and prep day. I don’t understand why my out put is wrong. its weird because in the first variable in doesn’t work, but the second temp variable the first function worked.
#include <iostream>
#include <string>
using namespace std;
class dayType
{
private:
string weekDay;
public:
static string weekDays[7];
dayType();
dayType(string d);
void setDay(string d);
string getDay() const;
void print() const;
string nextDay();
string prevDay();
void addDay(int nDays);
};
string dayType::weekDays[7] =
{
"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"
};
dayType::dayType()
{
weekDay = " ";
}
dayType::dayType(string d)
{
weekDay = d;
}
void dayType::setDay(string d)
{
weekDay = d;
}
string dayType::getDay() const
{
return weekDay;
}
void dayType::print() const
{
cout << weekDay << endl;
}
string dayType::nextDay() //const
{
for(int i = 0; i < 7; i )
{
if(weekDays[i] == weekDay)
{
string temp;
temp = weekDays[i 1];
weekDay = temp;
}
}
return weekDay;
}
string dayType::prevDay()
{
for(int i = 0; i < 7; i )
{
if(weekDays[i] == weekDay)
{
string temp;
temp = weekDays[i-1];
weekDay = temp;
}
}
return weekDay;
}
int main()
{
dayType myDay("Monday");
dayType temp("Sunday");
myDay.print();
cout << endl;
cout << myDay.prevDay() << endl;
cout << "here\n";
cout << myDay.nextDay() << endl;
temp.print();
cout << endl;
cout << temp.prevDay() << endl;
cout << "here2";
cout << temp.nextDay() << endl;
return 0;
}
Author
Account Strength
100%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
626
Link Karma
73
Comment Karma
235
Profile updated: 4 hours ago
Posts updated: 11 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/cpp_questio...