This program is suppose to input a date and output the day of the week that corresponds to that date. I have the program all done, but the code is not presented in the main() of the form. Im guessing i have to organize it a little more. any ideas would be appreciated! it doesent run at all.

Here is my code:

#include <iostream>
#include <cmath>
#include <string>
using namespace std;
void getInput(int &, int &, int &);
bool isLeapYear(int);
int getCenturyValue(int);
int getYearValue(int);
int getMonthValue(int, int);

void getInput(int &month, int &day, int &year)
{cout<<"Enter month: ";
cin>>month;
cout<<"Enter day: ";
cin>>day;
cout<<"Enter year: ";
cin>>year;
}
int main()
{  
	int month,mth,yr,cen,day, year,dow;
   string name;
    getInput(month,day,year);
    mth=getMonthValue(month, year);
    yr=getYearValue(year);
    cen=getCenturyValue(year);
    dow=(day+mth+yr+cen)%7;
    switch(dow)
       {case 0: name="Sunday";break;
       case 1: name="Monday";break;
       case 2: name="Tuesday";break;
       case 3: name="Wednesday";break;
       case 4: name="Thursday";break;
       case 5: name="Friday";break;
       case 6: name="Saturday";break;
      }            
   cout<<month<<"/"<<day<<"/"<<year<<"is a "<<name<<endl;
    system("pause");
    return 0;
bool isLeapYear(int year)
{if(  (year%400==0)  ||((year%4==0)&&(year%100!=0) ))
     return true;
else
     return false;
}
int getCenturyValue(int y)
{  int c,r;
    c=y/100;
    r=(c%4);
    return (3-r)*2;
}

int getYearValue(int y)
{   int yv;
    yv=y%100;
    return yv+(yv/4);
}
int getMonthValue(int m, int y)
	{  
	switch(m-1)
      {case 0: if(isLeapYear(y))
                  return 6;
              else
                  return 0;
        case 1:if(isLeapYear(y))
                  return 2;
              else
                  return 3;  
        case 2:
        case 10:return 3;
        case 3:
        case 6: return 6;
        case 4: return 1;
        case 5: return 4;
        case 7: return 2;
        case 11:
        case 8: return 5;
        case 9: return 0;
       }  
system("pause");
return 0;

}

You can't define a function inside another function. Look at Lines 39 and 40. Is something missing there? This is where you main() should end, but it doesn't end until Line 84.

By the way, I know that Line 84 doesn't exist, that's my point. You need to pay closer attention to the pairing of your braces.

I've re-formatted your code with proper indentation:

#include <iostream>
#include <cmath>
#include <string>
using namespace std;
void getInput(int &, int &, int &);
bool isLeapYear(int);
int getCenturyValue(int);
int getYearValue(int);
int getMonthValue(int, int);

void getInput(int &month, int &day, int &year)
{cout<<"Enter month: ";
  cin>>month;
  cout<<"Enter day: ";
  cin>>day;
  cout<<"Enter year: ";
  cin>>year;
}
int main()
{  
  int month,mth,yr,cen,day, year,dow;
  string name;
  getInput(month,day,year);
  mth=getMonthValue(month, year);
  yr=getYearValue(year);
  cen=getCenturyValue(year);
  dow=(day+mth+yr+cen)%7;
  switch(dow)
  { case 0: name="Sunday";break;
    case 1: name="Monday";break;
    case 2: name="Tuesday";break;
    case 3: name="Wednesday";break;
    case 4: name="Thursday";break;
    case 5: name="Friday";break;
    case 6: name="Saturday";break;
  }            
  cout<<month<<"/"<<day<<"/"<<year<<"is a "<<name<<endl;
  system("pause");
  return 0;
  bool isLeapYear(int year)
  { if(  (year%400==0)  ||((year%4==0)&&(year%100!=0) ))
      return true;
    else
      return false;
  }
  int getCenturyValue(int y)
  { int c,r;
    c=y/100;
    r=(c%4);
    return (3-r)*2;
  }

  int getYearValue(int y)
  { int yv;
    yv=y%100;
    return yv+(yv/4);
  }
  int getMonthValue(int m, int y)
  {  
    switch(m-1)
    { case 0: if(isLeapYear(y))
          return 6;
        else
          return 0;
      case 1:if(isLeapYear(y))
          return 2;
        else
          return 3;  
      case 2:
      case 10:return 3;
      case 3:
      case 6: return 6;
      case 4: return 1;
      case 5: return 4;
      case 7: return 2;
      case 11:
      case 8: return 5;
      case 9: return 0;
    }  
    system("pause");
    return 0;

  }

Notice how the final brace on Line 83 is still indented? It's not all the way over to the left. That's because you have your brace pairings wrong. You're missing one...

Edited 4 Years Ago by Fbody: n/a

Also, have you ever heard of SPACEs? Your blob-of-text format is very difficult to read. Take this blob:

int month,mth,yr,cen,day, year,dow;
  string name;
  getInput(month,day,year);
  mth=getMonthValue(month, year);
  yr=getYearValue(year);
  cen=getCenturyValue(year);
  dow=(day+mth+yr+cen)%7;
  switch(dow)
  { case 0: name="Sunday";break;
    case 1: name="Monday";break;

(where'd that space come from at day, year ) :icon_wink:
Reformatted so it's readable:

int  month, mth, yr, cen, day, year, dow;
  string name;
  
  getInput (month, day, year);
  
  mth = getMonthValue(month, year);
  yr  = getYearValue(year);
  cen = getCenturyValue(year);
  dow = (day + mth + yr + cen) % 7;
  
  switch(dow)
  { 
    case 0: 
      name = "Sunday";
      break;
    case 1: 
      name = "Monday";
      break;

Try it. You'll like it. And so will your instructor.

Alright guys thank you, idk why I forgot to use spaces and what not. and the scope brackets some how i got very confused on placing them, thanks guys!

Here is the final code (and it works) Thanks so much:

#include <iostream>
    #include <cmath>
    #include <string>
    using namespace std;
    
	void getInput (int &, int &, int &);
    int getCenturyValue (int);
    int getYearValue (int);
    int getMonthValue (int, int);
     
    void getInput(int &month, int &day, int &year)
    {
    cout << "Enter month: ";
    cin >> month;
    cout << "Enter day: ";
    cin >> day;
    cout << "Enter year: ";
    cin >> year;
    }
    int main()
    {
    int month, mth, yr, cen, day, year, dow;
    string name;
     
    getInput (month, day, year);
     
    mth = getMonthValue(month, year);
    yr = getYearValue(year);
    cen = getCenturyValue(year);
    dow = (day + mth + yr + cen) % 7;
     
    switch(dow)
    {
    case 0:
    name = "Sunday";
    break;
    case 1:
    name = "Monday";
    break;   
    case 2: 
    name = "Tuesday";
    break;
    case 3: 
    name = "Wednesday";
    break;
    case 4: 
    name = "Thursday";
    break;
    case 5: 
    name = "Friday";
    break;
    case 6: name = "Saturday";
    break;
    }
    cout << month << "/" << day << "/" << year <<" is a " << name <<endl;
    system("pause");
    return 0;
	}
   
    bool isLeapYear (int year)
    {
	if( (year % 400 == 0) || (( year % 4 == 0) && (year % 100 !=0) ))
    return true;
    else
    return false;
    }
   
    int getCenturyValue (int y)
    { int c, r;
    c=y / 100;
    r=(c % 4);
    return (3 - r) *2;
    }
     
    int getYearValue (int y)
    { 
	int yv;
    yv = y % 100;
    return yv + (yv / 4);
    }
    
    int getMonthValue (int m, int y)
    {
    switch(m - 1)
    {
	case 0: 
    if (isLeapYear(y))
    return 6;

    else
    return 0;

    case 1:
    if (isLeapYear(y))
    return 2;
    
    else
    return 3;
    case 2:
    
    case 10: 
    return 3;
    
    case 3:

    case 6: 
    return 6;

    case 4: 
    return 1;
    
    case 5: 
    return 4;

    case 7: 
    return 2;
   
    case 11:

    case 8: 
    return 5;
    
    case 9: 
    return 0;
    }
    system("pause");
    return 0;
     
    }

Alright guys thank you, idk why I forgot to use spaces and what not. and the scope brackets some how i got very confused on placing them, thanks guys!

Here is the final code (and it works) Thanks so much:

Unfortunately, you code now looks terrible. And if "the scope brackets" confused you, I now see what your problem is. You need to study this and you will never be confused again about your brackets and spacing. :icon_wink:

This question has already been answered. Start a new discussion instead.