porterrj 0 Newbie Poster

okay I came up with something a little more complex, but it's still not working. I know it's somewhere within my functions (either the bools or whatnot)......basically it's not telling them they entered an invalid date.

Any help?? I didn't put it in there, because I can't figure out where it goes logically.


/

************************Includes**************************************/

# include<iostream>
# include<iomanip>
using namespace std;

/************************Function call*********************************/

int isLeapYear(int year);                                //function
int dateIsValid (int day, int month, int year);          //function


/***********************Main******************************************/

int main()
	{
      int value1, value2, value3;
	  char again;

      do
	  {
			cout << "Enter the day, month, and year. \n";
			cin  >> value1 >> value2 >> value3;
			dateIsValid(value1, value2, value3);               //call function
			cout << value1<<" "<< value2 <<" "<< value3<<endl;
			cout << " Do you want to enter another date? (Y/N)";
			cin >>again;

	  }while (again =='Y' || again =='y');
      
	  return 0;
}

 /*************************FUNCTION*********************************/

    int dateIsValid(int day, int month, int year)

    {
		bool valid;
		int monthLength[13] =  { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    
		 if ( isLeapYear(year) )
             monthLength[2] = 29;    //  29 days in February in a leap year 

		if ( month < 1 || month > 12 )
        	valid = false;
	    else if ( day < 1 || day > monthLength[month] )
        	valid = false;

    return ( valid );

    }
    
 /****************************FUNCTION*******************************************/

    int isLeapYear(int year)
    {
       bool result;
    
       if ( (year%4) != 0 )               //  or:    if ( year%4 )
          result = false;                 //  means: if year is not …
porterrj 0 Newbie Poster

hello!

I need a program that validates the imput of dates. (Checks for leap years etc.)

The user enters: mm/dd/yyyy

The problem is, I have trouble with complex programs. I came up with this program, but i know it's too basic for what she wants. I need to have arrays in there, but i don't know how. I would love any help considering I'm bad at understanding this subject.

:)


could someone help me ???!!!

bool GoodDate(int month,int day,int year)


    {
    	/*** Bad Month ***/
    	if(month < 1 || month > 12)
    		return false;
    	
    	/*** January ***/
    	else if(month == 1)


        	{
        		if(day >=1 && day<= 31)
        			return true;
        		else
        			return false;
        	}
        	
        	/*** Febuary ***/
        	else if(month == 2) // divisible by 4 and either divisible by 400 or not divisible by 100


            	{
            		/*** if the year is a leap year... ***/
            		if(year % 4 == 0 && (year % 400 == 0 || year % 100 != 0))


                		{
                			if(day >= 1 && day <= 29)
                				return true;
                			else
                				return false;
                		}
                		/*** if the year is not a leap year... ***/
                		else

                    		{
                    			if(day >=1 && day <= 28)
                    				return true;
                    			else
                    				return false;
                    		}
                    	}
                    	
                    	/*** March ***/
                    	else if(month == 3)


                        	{
                        		if(day >=1 && day<= 31)
                        			return true;
                        		else
                        			return false;
                        	}
                        	
                        	/*** April ***/	
                        	else if(month == 4)


                            	{
                            		if(day >=1 && day<= 30)
                            			return true;
                            		else
                            			return false;
                            	}
                            	
                            	/*** May ***/	
                            	else …
porterrj 0 Newbie Poster

I just don't understand where I would add a "Margin" to???

I've tried all of the variables

porterrj 0 Newbie Poster

Think harder. A good night's sleep helps.

i have thought long and hard..........

It's due tomorrow at 8 AM.

I would love to sleep on it.....but seriously my mental capacity for figuring this out is less than a two-year old.

I've been trying for the past hour......how sad is that !!

Please help me.....!!! makes the difference between a C and a B.

porterrj 0 Newbie Poster

i have thought long and hard..........

It's due tomorrow at 8 AM.

I would love to sleep on it.....but seriously my mental capacity for figuring this out is less than a two-year old.

I've been trying for the past hour......how sad is that !!

Please help me.....!!! makes the difference between a C and a B.

porterrj 0 Newbie Poster

Okay, I think I understand the logic.

I'm so tired right now.....where would that fit in?? would I have to make another function?????

void displayStars (int, int);

int main ()
{ 
   int row, column;
   char again;

      do
           {
	
	cout << "Enter the number of rows and columns: ";
	cin >> row >> column;

	while (column < 2 || column > 60 && row < 2 || row > 60)
	{
	cout << "Invalid values for rows and columns" <<endl;
	cout << "Please enter values between 2 - 60: " ;
	cin >> row >> column;
	}
	cout << endl << endl;
	displayStars(row, column);										cout << endl << endl;
	cout << " Do you want to create another rectangle? (Y/N) ";
	cin >> again;
	} while (again == 'Y' || again == 'y');
	return 0;
} 


void displayStars(int width, int height) 
{
for (int across = 0; across < height; across++) 
	{
	for (int down = 0; down < width; down++) 
	{
	if ((down == 0) || (down == width - 1)) 
	{
	cout << "*";
	} 
	else if ((across == 0) || (across == height - 1)) 
	{
	cout << "*";
	 } 
	 else 
	{
	cout << " ";
	 }
            }
        cout << endl;
		}
}

Thanks soooo much :)

porterrj 0 Newbie Poster

Hello! I have a program that generates a rectangle based on width and height.

---I just need to figure out how to center this if the screen was 80 characters wide.------

void drawRect(int width, int height) {
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            if ((j == 0) || (j == width - 1)) {
                cout << "*";
            } else if ((i == 0) || (i == height - 1)) {
                cout << "*";
            } else {
                cout << " ";
            }
        }
        cout << endl;
    }
}
porterrj 0 Newbie Poster

Okay I see! It makes sense to me! THANKS A LOT :)

One more added detail, I need to make the rectangle centered.

I need to assume the screen is 80 characters wide.


THANKS A LOT :) OH man, I'm slow at this stuff. I need to start on my history exam!

porterrj 0 Newbie Poster

It didn't work. Oh no, i have another exam to study for tonight.

I've been sick and I'm so far behind.

This is my entire program:

#include <iostream>
using namespace std;


void displayStars (int, int);

int main ()
{ 
    int row, column;

    cout << "Enter the number of rows and columns: ";
    cin >> row >> column;

    while (column < 2 || column > 60 && row < 2 || row > 60)
    {
    cout << "Invalid values for rows and columns" <<endl;
    cout << "Please enter values between 2 - 60: " ;
    cin >> row >>column;
    }

    displayStars(row, column);      
    return 0;
} 


void displayStars (int rows, int cols)
{

   for (int across = 0; across < rows; across++)
     {
          if (across == 0 || across == rows)
    {
           for (int down = 0; down < cols; down++)
        cout << "*";
        cout << endl;
    }
           else
    {
            for (int down = 0; down < cols; down++)
               {
                               if (down == 0 || down == cols)
             cout << "*";
                               else
                                                  cout << "  ";
                              }
      }
       cout <<endl;
    }
}
porterrj 0 Newbie Poster

Hi I'm new to C++ and to here.

I have an assignment.

Make a HOLLOW rectangle using Functions.

Have the user imput the amount of rows and columns....and border width .

It should look something like this (It's supposed to be a HOLLOW rectangle) :

Enter number of rows and columns:
Enter Border width:


**********
*        * 
*        *
*        *
**********

I'm only able to get this:

***********
***********
***********
***********
***********

here's the part of my code that I know is affecting it :

//This function displays a square made of astericks

void displayStars (int rows, int cols)
{

for (int across = 0; across < rows; across++)
    {
         for (int down = 0; down < cols; down++)
         cout << "*";
         cout <<endl;
}
}
porterrj 0 Newbie Poster

Hi I'm new to C++ and to here.

I have an assignment.

Make a rectangle using Functions.

Have the user imput the row size and column width.

It should look something like this (It's supposed to be a rectangle...hollow) :

**********
*               *
*               *
*               *
**********

I'm only able to get this:

***********
***********
***********
***********
***********

here's my code ( I know it's something in my FOR loop) :

#include <iostream>
using namespace std;


//Function prototype


void displayStars (int, int);


int main ()
{
int row, column;


cout << "Enter the number of rows and columns: ";
cin >> row >> column;


while (column < 2 || column > 60 && row < 2 || row > 60)
{
cout << "Invalid values for rows and columns" <<endl;
cout << "Please enter values between 2 - 60: " ;
cin >> row >>column;
}


displayStars(row, column);
return 0;
}


//Definition of function displayStars


//This function displays a square made of astericks


void displayStars (int rows, int cols)
{
//Nested loop.  The outer loop controls the rows
//and the inner loop controls the columns.


for (int across = 0; across < rows; across++)
{
for (int down = 0; down < cols; down++)
cout << "*";
cout <<endl;
}
}