The following code is not working properly need assistance

Joined
Nov 16, 2022
Messages
1
Reaction score
0
I wrote the following code the main purpose was for it to display a previous day and the next day of the given day but it's returning a blank screen.
"
#include <iostream>
#include <string>
using namespace std;
class dayType {
public:
void print() const;
string setDay(string day);
string getPrevDay (string day) const;
string getNextDay() const;
dayType();
dayType(string day);
private:
string mon;
string tue; string wed; string thur; string fri; string sat; string sun; string day; string prevDay; string nextDay;
};
void dayType::print() const
{
cout<< day;
}
string dayType::setDay(string day)
{
string mon, tue, wed, thur, fri, sat, sun;
if ((day == "Monday") || (day == "monday")) {
day = mon;
} else if ((day == "Tuesday") || (day == "tuesday")) {
day = tue;
} else if ((day == "Wednesday") || (day == "wednesday")) {
day = wed;
} else if ((day == "Thursday") || (day == "thursday")) {
day = thur;
} else if ((day == "Friday") || (day == "friday")) {
day = fri;
} else if ((day == "Saturday") || (day == "saturday")) {
day = sat;
} else if ((day == "Sunday") || (day == "sunday")) {
day = sun;
} else cout << "Not a valid day. " << endl;
return day;
}
string dayType::getPrevDay(string day) const
{
if (day == mon) {
prevDay == sun;
} else if (day == tue) {
prevDay == mon;
}
return prevDay;
}
string dayType::getNextDay() const {
return nextDay;
} //Defaultconstructor
dayType::dayType()
{
day = "";
}
//Constructorwithparameters
dayType::dayType(string day) {
string today; day = today;
}
int main() {
string day;
cout << "Enter a day of the week: ";
cin >> day;
dayType today;
today.setDay(day);
today.getPrevDay(day);
today.getNextDay();
today.print();
return 0;
}"
 
Last edited:
Joined
Sep 21, 2022
Messages
122
Reaction score
15
1 convert the day name to an integer from 0 to 6
2 next_day = (day + 1) modulo 7
3 prev_day = (day + 8) modulo 7
4 convert the integers to names

The conversion can be done with IF statements, or an array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top