Need another set of eyes

I have been working on this project for 3 days and I just can not figure out how to solve these errors, was hopping someone could help, here is my code and my error messages:

#include <string>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

//Function Prototypes

void DetermineWeekDay(float day,float month,float year,long int JDN, long int intRes1,long int intRes2,long int intRes3,int& DayofWeek);


int main()
{

//Input variables
float day;
float month;
float year;
int DayofWeek;
long int intRes1 = 0;
long int intRes2 = 0;
long int intRes3 = 0;
long int JDN = 0;
bool dataOK = false;

do
{
cout << "Please enter the month";
cin >> month;

cout << "Please enter the week day:";
cin >> day;
cout << "Please enter the year:";
cin >> year;

if (month <= 10 && day <= 15 && year <= 1582) {
intRes1 = 0;
}

else
{
cout << "year / 100 = " << year / 100
<< ", year / 400 = " << year / 400
<< endl;
intRes1 = ((2 - year / 100) + (year / 400));
}
cout << "intRes1 = " << intRes1 << endl;



DetermineWeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek);
cin.get();
cin.get();
return 0;

}

//****************************************************************************************
void DetermineWeekDay (float day,float month,float year,long int JDN, long int intRes1,
long int intRes2,long int intRes3,int& DayofWeek);

{


intRes1 = (2-year / 100 + year / 400);
intRes2 = int(365.25 * year);
intRes3 = int(30.6001 * (month + 1));
JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5);

if (DayofWeek = ((JDN + 1) % 7)+1)
cout << " The day of the week " << " for " << month << day << year << "is" << DayofWeek << endl;

if (DayofWeek == 0)
cout << "Sunday" << endl;
else
if(DayofWeek == 1)
cout << "Monday" << endl;
else
if(DayofWeek == 2)
cout << "Tuesday" << endl;
else
if(DayofWeek == 3)
cout << "Wednesday" << endl;
else
if(DayofWeek == 4)
cout << "Thursday" << endl;
else
if(DayofWeek == 5)
cout << "Friday" << endl;
else
if(DayofWeek == 6)
cout << "Saturday" << endl;

return 0;

}


Errors:
Friedmann_Chapter9, Configuration: Debug Win32 ------
1> Friedmann_Chapter9.cpp
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(49): warning C4244: '=' : conversion from 'float' to 'long', possible loss of data
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(55): warning C4244: 'argument' : conversion from 'float' to 'long', possible loss of data
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(55): warning C4244: 'argument' : conversion from 'long' to 'float', possible loss of data
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(63): error C2062: type 'void' unexpected
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(69): warning C4244: '=' : conversion from 'float' to 'long', possible loss of data
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(72): warning C4244: '=' : conversion from 'double' to 'long', possible loss of data
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(101): fatal error C1075: end of file found before the left brace '{' at 'c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(17)' was matched
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Thanks for any help.
Your do-while loop is missing the while statement.
Thanks, I fixed that part of it but still getting the same error messages.
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
93
94
95
96
97
#include <string>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

//Function Prototypes

void DetermineWeekDay(float day,float month,float year,long int JDN, long int intRes1,long int intRes2,long int intRes3,int& DayofWeek);


int main()
{

//Input variables
float day;
float month;
float year;
int DayofWeek;
long int intRes1 = 0;
long int intRes2 = 0;
long int intRes3 = 0;
long int JDN = 0;
bool dataOK = false;

do
{
cout << "Please enter the month";
cin >> month;

cout << "Please enter the week day:";
cin >> day;
cout << "Please enter the year:";
cin >> year;

if (month <= 10 && day <= 15 && year <= 1582) {
intRes1 = 0;
}

else
{
cout << "year / 100 = " << year / 100
<< ", year / 400 = " << year / 400
<< endl;
intRes1 = ((2 - year / 100) + (year / 400));
}
cout << "intRes1 = " << intRes1 << endl;



DetermineWeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek);
cin.get();
cin.get();
return 0;

}

//****************************************************************************************
void DetermineWeekDay (float day,float month,float year,long int JDN, long int intRes1,
long int intRes2,long int intRes3,int& DayofWeek);

{


intRes1 = (2-year / 100 + year / 400);
intRes2 = int(365.25 * year);
intRes3 = int(30.6001 * (month + 1));
JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5);

if (DayofWeek = ((JDN + 1) % 7)+1)
cout << " The day of the week " << " for " << month << day << year << "is" << DayofWeek << endl;

if (DayofWeek == 0)
cout << "Sunday" << endl;
else
if(DayofWeek == 1)
cout << "Monday" << endl;
else
if(DayofWeek == 2)
cout << "Tuesday" << endl;
else
if(DayofWeek == 3)
cout << "Wednesday" << endl;
else
if(DayofWeek == 4)
cout << "Thursday" << endl;
else
if(DayofWeek == 5)
cout << "Friday" << endl;
else
if(DayofWeek == 6)
cout << "Saturday" << endl;

return 0;

}



Line 95, you are returning 0 in a function that was declared as void. Hmm, could you post your current code? Using the code blocks <> on the right please. :) Without your while statement in there it's a bit tougher to figure out the errors.
Last edited on
Ok I went back and worked on it and now I only get 4 warnings and I really don't know what else to do. The program compiles fine and reads the inputs correctly and outputs correctly. I am just stuck in these warning.

Code:
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
#include <string>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

//Function Prototypes
void DetermineWeekDay(float day,float month,float year, int JDN, int intRes1, 
int intRes2, int intRes3,int& DayofWeek);


int main()
{

//Input variables
float day;
float month;
float year;
int DayofWeek;
int intRes1 = 0;
int intRes2 = 0;
int intRes3 = 0; 
int JDN = 0; 
bool dataOK = false;


// Promtp user for inputs

cout << "Please enter the month as a number: ";
cin >> month;
cout << "Please enter the week day as a number: ";
cin >> day;
cout << "Please enter the year and a number: ";
cin >> year;

if (month<13)
dataOK = true;
else
cout << "Please enter a number less than 13 for the month: " 
<< endl;
if (day<32);
else
cout << "Please enter a number less than 32 for the day:" 
<< endl;

if((year>1582) ||   //Picks any years from Gregorian Calendar greater than 1582
(month>10) && (year==1582) ||   //Picks months greater than 10 in 1582 from Gregorian Calendar
(month== 10) && (day>15) && (year== 1582))   // Picks only month 10 and any days over 15 in year 1582 from Gregorian Calendar


 while (dataOK== false);

DetermineWeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek);
cin.get(), cin.get();
return 0;
}

//********************************************************************************************************************************
void DetermineWeekDay (float day,float month,float year, int JDN, int intRes1, 
int intRes2, int intRes3,int& DayofWeek)

{
intRes1 = (2-year / 100 + year / 400);
intRes2 = int(365.25 * year);
intRes3 = int(30.6001 * (month + 1));
JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5);
DayofWeek = ((JDN + 3) % 7); 

cout << " The day of the week is:  " << DayofWeek;
if (DayofWeek == 0)
cout << "Sunday";
else if (DayofWeek == 1) 
cout << "Monday";
else if (DayofWeek == 2) 
cout << "Tuesday";
else if (DayofWeek == 3) 
cout << "Wednesday";
else if (DayofWeek == 4)
cout << "Thursday";
else if (DayofWeek == 5) 
cout << "Friday";
else if (DayofWeek == 6) 
cout << "Saturday";
cout << endl; 

return;
}
//***************************************************************************************************************************
// End Program 


Errors/warnings:
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(57): warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(57): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(67): warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\friedmann\desktop\c++ projects\chapter 9\friedmann_chapter9\friedmann_chapter9\friedmann_chapter9.cpp(70): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1> Friedmann_Chapter9.vcxproj -> C:\Users\Friedmann\Desktop\C++ Projects\Chapter 9\Friedmann_Chapter9\Debug\Friedmann_Chapter9.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Thanks for everyone's help already.
why are day & month of type float?
My professor suggested to us that we might need to float them, was he wrong in saying that?
Unless you expect them to contain decimal values at any time, no you don't need need to use float. All those warnings mean if is you assign a value of say 1.5 to an int it'll be converted to 1. That's what loss of precision means. If you only deal with whole values you are fine with those warnings, or with simply making the floats ints instead. On lines 64 to 66 you are casting floats to ints though so that's where some of the warnings are coming from.

Also, why are you passing intRes1, intRes2 and intRes3 to your DetermineWeekDay function if you are just going to reassign their values to something else? You could simply declare them inside the function or, if they are needed globally, outside and not pass them to the function at all. You only need to pass values to a function if it uses those values and they are obtained outside the function.

And your while statement is there, but what happened to the do?

Line 42, you end the if with a ;. No need for that. Also, you don't have any code to be executed if the statement is true so it's a wasted test.

Line 47-49 you don't really need the parentheses around each expression there since they will each have a higher precedence then the || operator. In fact, that whole test expression is needlessly verbose now that I think about it. Exactly what are you testing for there? Because if the last set of 3 is true, then the first 2 sets are going to be true anyway. But, since you have each set split by || as long as the year is greater then 1582, the whole expression will evaluate as true since in an or statement once one of the test expressions evaluates as true the rest aren't even considered. It's just confusing how that whole thing would turn out and prolly doesn't do what you expect it to. :)

And lastly DayofWeek is of type int. In your call you are passing it by value to your function, yet the function declaration says it is expecting the address of DayofWeek. Since it's only an int there's no issue passing it by value, especially since the function doesn't return anything.
Last edited on
Ah yes, I remember when I did this about 20 years ago there was a formula for calculating the number of days since the start of the current calendar.

The compiler is warning you because of the potential loss of data, because going from floating point to an integral type looses the decimal fraction part. If you are not worried about that then do an explicit cast, and the warnings will go away. You will have to check this doesn't cause a problem.

Go read about static_cast in the reference section.
Thank you for everyone's help so much!
Topic archived. No new replies allowed.