I have an error on line 7 this is what it is telling me.
I do not know if the code works because I can not build it. Any help will be greatly appreciated.
Error 1 error C2447: '{' : missing function header (old-style formal list?)
include <iostream>
#include <cstdlib>
usingnamespace std;
int serial_julian_date(int month, int Day, int Year);
{ // this is where my error is .
int a = (14 - Month) / 12;
int m = Month + 12 * a - 3;
int y = Year + 4800 - a;
int nDate =
Day + ((153 * m + 2) / 5) +
365 * y + y / 4 - y / 100 + y + y / 400 - 32045;
return nDate;
}
int main()
{
cout
<< "Enter the date in MM DD YYYY(seperated by spaces)"
<< "format(seperated by spaces) :";
cout << "Serial Julian date is :";
int Month;
int Day;
int Year;
cout << serial_julian_date(7, 4, 1776) << '\n';
keep_window_open();
return 0;
}
Thanks I just started my C++ course with no knowledge of programing. Can someone tell me where the cin>> should be and what I should be putting in there. I am lost everything I have tried will not work. I can not get user input in .
#include "std_lib_facilities.h"
#include <iostream>
//function declaration
int serial_julian_date(int Month, int Day, int Year)
{
int a = (14 - Month) / 12;
int m = Month + 12 * a - 3;
int y = Year + 4800 - a;
int nDate =
Day + ((153 * m + 2) / 5) +
365 * y + y / 4 - y / 100 + y + y / 400 - 32045;
return nDate;
}
int main()
{
cout
<< "Enter the date in MM DD YYYY(seperated by spaces)"
<< "format(seperated by spaces)\n";
cout << "Serial Julian date is :" ;
cout << serial_julian_date(7, 14, 1446) << '\n';
keep_window_open();
return 0;
}
Judging by the way that you've coded so far, you would want something like this -
1 2 3 4 5 6 7 8 9 10
cout << "Enter the date in MM DD YYYY(seperated by spaces)" << endl;
cout << "Serial Julian date is : ";
int month, day, year;
cin >> month >> day >> year; // user enters month, day and year seperated by space.
int x = serial_julian_date(month, day, year); // call for the julian function. Give them the user info and catch the returning nDate with int x.
cout << endl << x << endl; // print the shit out.
Hey thanks for the help , That is how I had it originally. Not as nicely coded. I am getting a year undefined error on the cin line that is stopping me from building it. Any ideas?
#include "std_lib_facilities.h"
#include <iostream>
//function declaration
int serial_julian_date(int Month, int Day, int Year)
{
int a = (14 - Month) / 12;
int m = Month + 12 * a - 3;
int y = Year + 4800 - a;
int nDate =
Day + ((153 * m + 2) / 5) +
365 * y + y / 4 - y / 100 + y + y / 400 - 32045;
return nDate;
}
int main()
{
cout
<< "Enter the date in MM DD YYYY(seperated by spaces)\n" << endl;
cout << "Serial Julian date is :" ;
int Month, Day, Year;
cin >> Month >> Day >> year; // error here
int x = serial_julian_date(Month, Day, Year);
cout << endl << x << endl;
Uhm yeh. Look at the line above - int Month, Day, Year;
Its Year, with a big Y. on the line after you type in year, with a small y.
The "good programming practice" way of doing things is, most things is to be named by starting off with a lower case letter(meaning, if its only 1 word like year or month, just name it int year; int paparaja; etc), and if the variable or function name is 2 or more words, just start the other words with an upper case, something like this - int testingThisShit;
But not classes. You want classes to start with uppercase letter.