Code compiles successfully, yet previous day is blank

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 

//#include "stdafx.h"
#include<iostream>
#include<cmath>

using namespace std;

//class declaration

class dayType{
public: int presday;
int prevday;
int nextday;
dayType ()
{
presday=0;
nextday=0;
prevday=0;
}

void set (int day); //function declarations
void print (int day);
int Next_day (int day);
int day();
int prev_day (int pres);
};
void dayType::set (int day) //member functions
{
presday=day;
}

int dayType::prev_day(int day)
{
prevday=presday-day;// =abs(presday-day);
if(prevday<0)prevday+=7;
return prevday;
}
int dayType::day()
{
return presday;
}

int dayType::Next_day(int day)
{
nextday=presday+day;
if(nextday>7)
{
nextday=nextday%7;
}
return nextday;
}
void dayType::print(int d)
{
if(d==1)
cout<<"Monday"<<endl;
if(d==2)
cout<<"Tuesday"<<endl;
if(d==3)
cout<<"Wednesday"<<endl;
if(d==4)
cout<<"Thursday"<<endl;
if(d==5)
cout<<"Friday"<<endl;
if(d==6)
cout<<"Saturday"<<endl;
if(d==7)
cout<<"Sunday"<<endl;
}

int main()
{
int d,p,n;
dayType obj;
cout<<"1-Mon"<<endl<<"2-Tue"<<endl<<"3-Wed"<<endl<<"4-Thur"<<endl<<"5-Fri"<<endl<<"6-Sat"<<endl<<"7-sun"<<endl;
cout<<"Enter Day";
cin>>d;
obj.set(d);
cout<<"Present day is";
obj.print(d);
cout<<"Enter number of days next";
cin>>d;
n=obj.Next_day(d);
cout<<"Next day is";
obj.print(n);
cout<<"Enter number of days previous";
cin>>d;
p=obj.prev_day(d);
cout<<"previous day is";
obj.print(p);
//("Pause");
}


So everything works perfectly, well not everything lol. Code compiles successfully without any errors but previous day does not calculate. In a sense that when it asks for number of previous days it returns a blank statement.
For example: Previous number day is: shows nothing

Any ideas what i might have missed??? maybe a sign or something. i keep going over and over but no errors kinda making it hard to find what am i missing.

Thanks guys
Line 36: if(prevday<0)prevday+=7;
What if prevday is -10?
Ok, nevermind guys. fixed the stupid error

1
2
3
4
5
6
int dayType::prev_day(int day)
{
prevday=presday-day;// =abs(presday-day);
if(prevday<0)prevday+=7; //should have been (prevday<=0)
return prevday;
}


Thanks
Topic archived. No new replies allowed.