gazoo 0 Light Poster

Hello mitrmkar,

Thanks for the pointer; I never thought that such info out there. I mod the code and it work, except the last part did work right, it suppose to display [display] Fun isn't it? [/display] but it display

?Fiinnsttu

, and how can I get around without using the #include <algorithm> instructor might not like it if I use it

#include <iostream>
#include <algorithm>

int main()

{
			using namespace std;
			int arr_size = 13;
			int arr[] = {80, 127, 120, 42, 115, 125, 120, 49, 126, 42, 115, 126, 73};
			cout << "Display numbers in the array before sort" << endl;
					for(int i=0; i < arr_size; i++)
			cout << " Integer [arr]: " << arr[i] << endl;
			cout << endl;
			
					sort(arr, arr + arr_size);
  			cout << "Display numbers in the array after sort" << endl;
			for(int i=0; i < arr_size; i++)
			cout << " Integer [arr]: " << arr[i] << endl;

			//Calculate the average value
			double total = 0.0;
			for(int i = 0; i < arr_size; i++)
				total += arr[i];
			double ave = total / arr_size;

			//report the results
			cout << " Average value = " << ave << endl;

			//Display numbers above the average
			cout << "Display number above average" << endl;
			for(int i=0; i < arr_size; i++)
				if(arr[i] > ave)
					cout << " Integer [arr]: " << arr[i] << endl;
			//Display numbers below the average
			cout << "Display number below average" << endl;
			for(int i=0; i < arr_size; i++)
				if(arr[i] < ave)
				cout << " Integer …
gazoo 0 Light Poster

I see, I’m new to this site and thought this person may still hook. I turned in this assignment and instructor was complained that I did not do what assignment required, I suppose to use the sort function to sort int arr and display it before and after sort. I was searching this site to see how other people used the sort function, and then I found this thread, which is similar to what I want to do. I used the sort function but did not compile have error.
[error]
error C3861: 'sort': identifier not found
[error]

Even if it compile pass the sort function point, it seem that the code is missing something.

gazoo 0 Light Poster

Hello bsdpowa,

I see what you saying about the sort function, but I try the way you have shown on my code it did't work, I want to use sort function to display the array that I assigned before sort and after sort. Without using sort just indexing it work fine but when I use the sort functin then it didn't work.

#include <iostream>

void display(int arr[], int size);

int main()

{
			using namespace std;
			//int arr[13] = {80, 127, 120, 42, 115, 125, 120, 49, 126, 42, 115, 126, 73};
const int size = 13;
int arr[size] = {80, 127, 120, 42, 115, 125, 120, 49, 126, 42, 115, 126, 73};
sort(arr, size);
			cout << "Display numbers in the array" << endl;
			for(int i=0; i < size; i++)
			cout << " Integer [arr]: " << arr[i] << endl;

			//Calculate the average value
			double total = 0.0;
			for(int i = 0; i < 13; i++)
				total += arr[i];
			double ave = total / 13;

			//report the results
			cout << " Average value = " << ave << endl;

			//Print numbers above the average
			cout << "Display number above average" << endl;
			for(int i=0; i < 13; i++)
				if(arr[i] > ave)
					cout << " Integer [arr]: " << arr[i] << endl;
			//Print numbers below the average
			cout << "Display number below average" << endl;
			for(int i=0; i < 13; i++)
				if(arr[i] < ave)
				cout << " Integer [arr]: " << arr[i] << endl;
			cout << "Display characters for the …
gazoo 0 Light Poster

Can anyone tell me what is this, to me it look like struct in a struct, if I were to write the OOP program to sort an array 5 of these object variables, where would I start?? What will be the out put should look like?? Can someone give an example???? Istart out then :icon_confused:

#include <iostream>
#include <string>

using namespace std;

void sort(object* arr, int num);

int mian()
{

struct object

{
    bool (*compare) (object first, first, object second);
    void (*display) (object in);
    union
    {
        int intVal;
        char* strVal;

    };

};


cin.get();
return (0);
}
gazoo 0 Light Poster

I have this program that suppost to ask user to select option:
[option]
a. Start a new list
b. Add a Node to the end of the list.
c. Add a Node to the beginning of the list.
d. Add a Node at a specified position in the list.
e. Walk the linked list, displaying all the "person" data.
f. Remove a Node at a specified position from the list. g. Delete the entire list.
[/option]
using double linked list, the code crashed with these errors:
[error]
error C2065: 'node' : undeclared identifier
error C2065: 'current' : undeclared identifier
error C2182: 'StartnewNode' : illegal use of type 'void'
fatal error C1903: unable to recover from previous error(s); stopping compilation
[error]

I don't see the problem, can anyone help me see what I did so wrong that it is failed so badely.

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

//void InitializeNode();
void StartnewNode(node *current);
void add_node_at_end();
void add_node_at_start(string new_name);
void InsertNode(node *current, node *After);
void displayNode(node *current);
void RemoveNode(node *current);
void DeleteAllNodes();

//linked list for the per_names  
struct Node
{														 
char* per_name[20];	 									 
Node *prev;//pionter to the previous node	 		   										  
Node *next;//pionter to the next node; 		 
};

 node *current;
 noe *After;
//create header node list
current = new node;
current->char* = per_name;
current->next = NULL;
current->prev = NULL;

Node *first;
Node *last;


int main()
{		
		for (int i=0; i < 5; i++)
		{
		//current = new NODE;
		current …
gazoo 0 Light Poster

Apriciated you guys help, I was able to used the find() function and was very nice if I want to find a string within a string.

Since you need to use c-style strings have a look at the below links:

http://www.daniweb.com/code/snippet314.html
http://www.daniweb.com/code/snippet262.html
http://www.cplusplus.com/reference/clibrary/cstring/strstr.html

gazoo 0 Light Poster

Hi Ancien Dragon,

Want to thank you very much for all your help, I got the code to compiled and working, what is this line do??

for ( i = input.find ( rem, 0 ); i != std::string::npos;

what is "npos", I don't see it declare any where. I need to use "char* strings" instead of "std::string", the instructor do not like us to use "std::string". I know this code work and I don't want to change anything, but for now we have too change it to use "char* string", how can I do that in this code??? when I done with the class then I can use what ever I want ha ha.

Regards,

>>I have added the code you have show below and I got errors:
Because you didn't put the code inside a function

gazoo 0 Light Poster

Hello Ancien Dragon,

Good to hear from you again, I have added the code you have show below and I got errors:

void Remove(int );
//string str1 = "abdxyzdxyz";
//string str2 = "xyz";
char* str1 = "abdxyzdxyz";
char* str2 = "xyz";

size_t pos;											//****************************
while( (pos = str1.find(str2)) != string::npos);	//I added this part to see if*
{													//it work.		     		 *
      string str3 = str1.substr(0 , pos);			//			        		 *
      if( (pos + str2.length() + 1) < str1.length())//							 *
        str3 += str1.substr(pos + str2.length() + 1);//**************************/
      str1 = str3;
}

//current_length = str1.length();

int main()

[error]
error C2059: syntax error : 'while'
error C2447: '{' : missing function header (old-style formal list?)
warning C4018: '<' : signed/unsigned mismatch
[/error]

try this:

string s1 = "abdxyzdxyz";
string s2 = "xyz";
size_t pos;
while( (pos = s1.find(s2)) != string::npos)
{
      string s3 = s1.substr(0,pos);
      if( (pos+s2.length() + 1) < s1.length())
        s3 += s1.substr(pos+s2.length()+1);
      s1 = s3;
}
gazoo 0 Light Poster

Hello everyone,

I have a code that use function to find and remove all occurrences of a string within a string (substring pending) and return the number of removals: I need to remove "xyz" in "abdxyzdxyz" the result should be "abdd" and a return of 2 removed. I used the debuger step into, it keep shown that "Removals = o" and the sbstring value = "abd", missing one character of "d". I can't see if I missed something, can some one help me see what I did wrong please.

#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

void Remove(int );
//string str1 = "abdxyzdxyz";
//string str2 = "xyz";
char* str1 = "abdxyzdxyz";
char* str2 = "xyz";

//current_length = str1.length();

int main()
   {
   char substring[4];
   int prev_occurence = 0;
   int removals = 0;
   int removed_occurence=0;
   

   for(int i=0; i < strlen(str1); i++)
   {
	   if(i % strlen(str2) == 0)
	   {
		   if(prev_occurence == 0)
			memcpy(&substring, &str1[prev_occurence], 3);
		   else
			   memcpy(&substring, &str1[prev_occurence], 3);
			substring[3] = '\0';
		   cout << substring;
		   removed_occurence = prev_occurence;
		   prev_occurence = i;
		   if(strcmp(str2, substring) == 0)
		   //if(strcmp(str2,substring) == 0)
			{
				
				Remove(removed_occurence);
				//Remove(prev_occurence - strlen(str2));
				//removed_occurence = prev_occurence - strlen(str2);	
				removals++;
			}
	   }
   }

   cout << "Removals = " << removals << endl;
getch();
   return 0;
   } 
void Remove(int prev_occurence)
{
	char another_string[50];
	//current_length -= 3;

	//another_string.copy(str1, str1.length());
	memcpy(&another_string, &str1[prev_occurence], strlen(str1) - prev_occurence);
	another_string[strlen(str1) - prev_occurence] = '\0';
	memcpy(&str1[prev_occurence], another_string, strlen(another_string));
	str1[prev_occurence + strlen(another_string) + 1] = '\0';
}:icon_sad:
gazoo 0 Light Poster

yes, it work very good. Some one may need and can use this code.

Thanks,

is it working now??

gazoo 0 Light Poster

Hello joshmo,

Thanks for your replied, actually I have added the

if (j == 0) 
                    { 
                    cout << "A" << endl; 
                    }  
                     else 
                        { 
                         cout << "B" << endl;
                        }

to display where I test "j" and added 1 to "i".

you declared arrays arr1 and arr2 but they are not used anywhere...anyway you want to access a seat which is supposed to be stored in an array..so to display this your supposed to access that array...i think the arr1 and arr2 should help you in this...your supposed to do some sort of handling so that when the name is input, a seat in the array is made unavailable and that seat is what should be displayed

gazoo 0 Light Poster

Hello joshmo,

Thanks for your replied, actually I have added the

if (j == 0) 
                    { 
                    cout << "A" << endl; 
                    }  
                     else 
                        { 
                         cout << "B" << endl;
                        }

to display where I test "j" and added 1 to "i".

you declared arrays arr1 and arr2 but they are not used anywhere...anyway you want to access a seat which is supposed to be stored in an array..so to display this your supposed to access that array...i think the arr1 and arr2 should help you in this...your supposed to do some sort of handling so that when the name is input, a seat in the array is made unavailable and that seat is what should be displayed

gazoo 0 Light Poster

I have this little program that assign seat for ailine passenger, it's work, but I want to add so that it display the name of (passenger = seat number) so far I only got it to display the passenger name in the spot of that seat number. I try set_num then I get and error, if I use NumSeats it display that passenger name = 11, it suppost to display passenger name = 1A, 1B......etc. Can anyone tell me what I need to do here

#include <iostream> 
#include <cctype>
#include <string>
#include <cstring>
using namespace std;

//Declare function proto type
int assignSeat(int seat_num, int row_num, int pass_num);
int num1(char*);
int num2(char*);

int NumSeats = 12;

void InitializeSeats();
void Reserve();
void Cancel();
void ChangeSeat();
void Display();

struct Seat 
  {
      char pass_name[80];
      int Available;
  };
  
  struct Seat SeatArray[6][2];
  
int main()
{      
   char seatchioce = 0;
   int row_num = 6;
   char a = 0;
   char w = 0;
  
  int total_passenger = 12;
   
  char arr1[][6] = {"1A","2A","3A","4A","5A","6A"};
  char arr2[][6] = {"1B","2B","3B","4B","5B","6B"};
    
  int MenuChoice;

  InitializeSeats();
  while(1)
  {
      cout << " 1. Reserve" << endl;
      cout << " 2. Cancel" << endl;
      cout << " 3. Change Seat" << endl;
      cout << " 4. Display" << endl;
      cout << " 5. Exit" << endl;

      cout << "Enter your choice: ";
      cin >> MenuChoice;

    if((MenuChoice < 0) && (MenuChoice > 5))
    {
      cout << "Invalid Choice" << endl;
      system("Pause Try Again");
    }
    else
    {
        switch(MenuChoice)
        {
            case 1: Reserve();
                break;
            case 2: Cancel();
                break;
            case 3: …
gazoo 0 Light Poster

Have ever got your code working??
I just got to that assignment and has some toruble adding the 2 diagonals = 30
I put all my function in Myfunction.h, I have main.cpp and functionCall.cpp. It did't add Diaginals correctely.

this in the header

// Function proto type
int Rows (int Ro[3][3]);
int Columns (int Co[3][3]);
int num(int C[3][3]);

this main.cpp

#include <iostream>
#include "Myfunction.h"


int main()

{
        using namespace std;

        //Declare 2-D arrays
        const int A = 3;
        const int B = 3;
        int C[A][B] = // initialize the first 2-D array
        {
            {1,2,3}, //values for C[0]
            {4,5,6}, //values for C[1]
            {7,8,9} //values for C[2]
        };

        cout << "They sum to: " << num(C)<< endl; // Display the output

        cin.get();
        return 0;

}

this is FunctionCall.cpp

#include <iostream>
#include "Myfunction.h"
using namespace std;


int num(int D[3][3])
{

    int A = 3;
    int B = 3;
        int i,j;
        int sum = 0;
             for(i = 0; i < A; i++)
                for(j = 0; j < B; j++)
                    sum += D[i][j];// Perform addition
        return sum;
}

i got it thanks for relpying

gazoo 0 Light Poster

Sorry here the complete code,

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

//Declare the function
bool leapyear(int year);

struct // struct declaration
{
	int Month;
	int Day;
	int Year;
	
}date;

int main()
{
		      				
	// Intialize Array For Number Of Days In Each Month
	static int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	//int months[12]= {0,31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month
	//Initialize array for number of month in the year
	//const unsigned int string_month = 12;
	static string arr[12]={"January ","February ","March ","April ","May ","June","July ","August ","September ","October ","November ","December "};

	//string arr[string_month] = {"January","February","March","April","May","June","July","August","September","October","November","December"}; 
	                                                                          
	int mm, dd, yyyy, year = 0;
	
	cout << "This program will display date and convert number of month to string" << endl;
	//Prompts user for input
    cout << "Enter month in the form of mm: ";
    cin >> mm;//Get month from input
  if( mm < 1 || mm > 12 )// Validate to see if input for month is valid
		 {
         cout << "INVALID month: Please try again.\n" << endl;
		 //cin.get();
		 system ("pause");
		 exit (1);
         }
	cout << "Enter day in the form of dd: ";
	cin >> dd;//Get day from input
  if( dd < 1 || dd > months[mm-1] )// Validate to see if input for day is valid for the month
		 {
         cout << "INVALID day: Please try again.\n" << endl;
		 cin.get();
		 system ("pause");
		 exit (1);
		 }
	cout << "Enter year in the form of yyyy: ";
	cin >> yyyy;//Get year from input
	cin.get();
	year = yyyy;
	cout << "You have entered: " << …
gazoo 0 Light Poster

Hello Ancient Dragon,

Thaks for the tips on (mod) operation, as right now my leap year program when enter no metter what year it alway display it is a leap year, it nerver got pass that piont to check if it is leap year or not.

gazoo 0 Light Poster

I see, like this little program that I wrote to convert integer to binary with remainders of 2:

#include <iostream>

int main()

{
	using namespace std;
	int x = 23;
	
	
	cout << "This program will convert integer number to binary\n";
	cout << "Integer number:23 ",
	cout << "Integer " << x << " = ",
	cout << x / 16 % 2
		 << x / 8 % 2
		 << x / 4 % 2
		 << x / 2 % 2 
		 << x / 1 % 2 << " in binary" << endl;
	cin.get();
	return 0;
}
gazoo 0 Light Poster

I see your piont, for logical thinking this the way to do it, when we talking about divisible by 4 or by 100 or by 400 in my mind it is

if(yyyy / 4 ==0)

, the (%) is dealing with remainder. Why are we using

if(yyyy % 4 == 0)

instead of the one above, unless we only dealing with the remainder only, now that doesn't make sent?????

if( year % 4 == 0) Most of the time if that is true then year is a leap year. 2001 is NOT a leap year because it is not evenly divisible by 4. 2004 IS a leap year because it is evenly divible by 4.


http://www.dataip.co.uk/Reference/LeapYear.php

gazoo 0 Light Poster

Hello tesuji,

Thanks for clarification, in that case 365 days/year is no longer a fact, therefore someone that write the program to calculate the leapyear or check for leap year need to take this as cinsideration.

gazoo 0 Light Poster

If I'm mistaken then there something wrong with my code, it tell me that 2004 or 2001 is not the leap year, I should stop working on this code, and if I continue working on it I will turn to roasted nut.

You are mistaken. It was a leap year.

gazoo 0 Light Poster

OK Sky Diploma,

You are correct, sorry about the confusion, seem like this leap year assignment is very popular. Who has invented the leap year must notice that earth rotation is got slower in that particular year, it take an extra 24 hrs to completed the year. You guys are awesome, thanks for all your help.

Regards,

KMH

All the numbers starting from 0 and divisible by four are leap years.

if(year%4==0)
{
cout<<"THIS IS A LEAP YEAR" <<year;
}

Am i not correct?
(Ps: the above code is not related to your program. Sorry.!!)

gazoo 0 Light Poster
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

//Declare the function
bool leapyear(int year);

struct // struct declaration
{
	int Month;
	int Day;
	int Year;
	
}date;

int main()
{
		      				
	// Intialize Array For Number Of Days In Each Month
	static int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	//int months[12]= {0,31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month
	//Initialize array for number of month in the year
	//const unsigned int string_month = 12;
	static string arr[12]={"January ","February ","March ","April ","May ","June","July ","August ","September ","October ","November ","December "};

	//string arr[string_month] = {"January","February","March","April","May","June","July","August","September","October","November","December"}; 
	                                                                          
	int mm, dd, yyyy, year = 0;
	
	cout << "This program will display date and convert number of month to string" << endl;
	//Prompts user for input
    cout << "Enter month in the form of mm: ";
    cin >> mm;//Get month from input
  if( mm < 1 || mm > 12 )// Validate to see if input for month is valid
		 {
         cout << "INVALID month: Please try again.\n" << endl;
		 //cin.get();
		 system ("pause");
		 exit (1);
         }
	cout << "Enter day in the form of dd: ";
	cin >> dd;//Get day from input
  if( dd < 1 || dd > months[mm-1] )// Validate to see if input for day is valid for the month
		 {
         cout << "INVALID day: Please try again.\n" << endl;
		 cin.get();
		 system ("pause");
		 exit (1);
		 }
	cout << "Enter year in the form of yyyy: ";
	cin >> yyyy;//Get year from input
	cin.get();
	year = yyyy;
	cout << "You have entered: " << mm << "-" << dd …
gazoo 0 Light Poster

I have a simular program, I'm a little confuse by leap year. I thought if leap year and divisible by 4 the month is February then days range 1-29 else 1-28 then it is not leap year? I think I got my code reverse.

gazoo 0 Light Poster

Here is the complete code, it work but not sure, the array I have increased to:
int months[14]= {31,28,31,30,31,30,31,31,30,31,30,31}; enable to cover date 29 for february month. and not sure if the line: if( dd < 1 || dd > months[dd-1] ) work correctely?? and I repeat this line like the one above: else if(leapyear(year)&& mm == 2) if I remove this line it complained.

#include <iostream>
#include <string>
#include <math.h>

using namespace std;

//Declare the function
bool leapyear(int year);
	
struct // struct declaration
{
	int Month;
	int Day;
	int Year;
	
}date;

int main()
{
		      				
	// Intialize Array For Number Of Days In Each Month
	int months[14]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month
	//Initialize array for number of month in the year
	const unsigned int string_month = 12;
	string arr[string_month] = {"January","February","March","April","May","June","July","August","September","October","November","December"}; 
	                                                                          
	int mm, dd, yyyy, year = 0;
	
	cout << "This program will display date and convert number of month to string" << endl;
	//Prompts user for input
    cout << "Enter month in the form of mm: ";
    cin >> mm;//Get month from input
  if( mm < 1 || mm > 12 )// Validate to see if input for month is valid
		 {
         cout << "INVALID month: Please try again.\n" << endl;
		 //cin.get();
		 system ("pause");
		 exit (1);
         }
	cout << "Enter day in the form of dd: ";
	cin >> dd;//Get day from input
  if( dd < 1 || dd > months[dd-1] )// Validate to see if input for day is valid for the …
gazoo 0 Light Poster

I see, thanks for the tips.

stop using inlinecode and adding your own color tags. It makes it very difficult to copy/paste into my own compiler. Use standard code tags and your program will be color coded.

gazoo 0 Light Poster

Ancient Dragon ,

Thanks for all your help, I have work on this code too long now, I have all the syntax and it work but not well. Seem like I can't enter number dd =29 for the month of February. The line highlighted it seem not respond to input off dd = 29. I have to inceased the number of an array element from int months[12] to int months[14], please see the completed code below.

#include <iostream>
#include <string>
#include <math.h>

using namespace std;

//Declare the function
bool leapyear(int year);
	
struct // struct declaration
{
	int Month;
	int Day;
	int Year;
	
}date;

int main()
{
		      				
	// Intialize Array For Number Of Days In Each Month
	int months[14]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month
	//Initialize array for number of month in the year
	const unsigned int string_month = 12;
	string arr[string_month] = {"January","february","March","April","May","June","July","August","September","October","November","December"}; 
	                                                                          
	int mm, dd, yyyy, year = 0;
	
	cout << "This program will display date and convert number of month to string" << endl;
	//Prompts user for input
    cout << "Enter month in the form of mm: ";
    cin >> mm;//Get month from input
  if( mm < 1 || mm > 12 )// Validate to see if input for month is valid
		 {
         cout << "INVALID month: Please try again.\n" << endl;
		 //cin.get();
		 system ("pause");
		 exit (1);
         }
	cout << "Enter day in the form of dd: ";
	cin >> dd;//Get day from input
  if( dd < 1 || dd > months[dd-1] )// …
gazoo 0 Light Poster

Hi Ancient Dragon,

You guys are great, this web site is very useful and valuable to me, your responses are tremendous. I really respect and thank you very much for your help, in that respect, I want to donate some money to keep this site alive for everyone like my self the C++ beginner. I know I have asked many questions this because in20 years I have not expose to C++ or write any programs, I apologize if I asked dump questions that may upset someone. Can you guys tell me how can I make my contribution (donate some money) to this site???:)

Beast Regards,

gazoo

gazoo 0 Light Poster

Hello Tymk,

Thanks for piont that out, I have spend more times on syntax then code structure. This part of code still not work right, I can not enter and dd > 27 (02-27-08) unless I increase the array size: int months[14]= {31,28,31,30,31,30,31,31,30,31,30,31}; and still did not display February, 29 2004 if it is a leapyear, man I can do this leap year faster in my head then write this program.:confused:

cout << "You have entered: " << mm << "-" << dd << "-" << yyyy << " which: ";
	//cout << arr[mm - 1] << ", " << date.Day << " " << date.Year << endl;
	{
	lp_ck = yyyy%4;
	//if(lp_ck==0)
	if(leapyear(year))
	{
	  months[1]=29;
	  cout << yyyy << " is a leap year.\n";
	}
    else
	{
      months[1]=28;
	  cout << yyyy << " is not a leap year\n";
	}
       }
gazoo 0 Light Poster

Hello Ancient Dragon,

so far I got it working without any problem, one thing that I still didn't feel right about this code is that, what if user enter 02-28-2004, it tell yes that is the leapyear, but it didn't correct the date entered, it should display 2004 is the leapyear: February, 29 2004. Another problem is that if user entered 02-29-2004, then it just need to display yyyy is leapyear: February, 29 2004. This code got too complicated, all I want it to do is display the leapyear if divisible by 4 then days range from 1-29, else it is not the leapyear day range from 1-28. Frustrations, I give up:icon_sad:

year = yyyy;
    cout << "You have entered: " << mm << "-" << dd << "-" << yyyy << " which: ";
    cout << arr[mm - 1] << ", " << date.Day << " " << date.Year << endl;
    {
    lp_ck = yyyy%4;
    lp_ck = yyyy%4;
    if(lp_ck==0)
    if(leapyear(year))
      months[1]=29;
      cout << yyyy << " is a leap year.\n";
    else
      months[1]=28;
      cout << yyyy << " is not a leap year\n";
    }

    //if(leapyear(year))
        
        //cout << yyyy << " is a leap year.\n";
    //else
        //cout << yyyy << " is not a leap year\n";

I changed the code in check for leapyear part, it tell me that I error:
[error]
error C2181: illegal else without matching if
[error]

gazoo 0 Light Poster

Hi Ancient Dragon,

I'm very close get this code working, it compiled and work fine but if entered 02-28-2004, then 2004 is a leapyear. If it is leapyear then it should display February, 29 2004 instead?? I thing I missing this part in the code.

#include <iostream>
#include <string>
#include <math.h>

using namespace std;

//Declare the function
bool leapyear(int year);
	
struct // struct declaration
{
	int Month;
	int Day;
	int Year;
	
}date;

int main()
{
		      				
	// Intialize Array For Number Of Days In Each Month 
	int months[13]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month
	//Initialize array for number of month in the year
	const unsigned int string_month = 12;
	string arr[string_month] = {"January","february","March","April","May","June","July","August","September","October","November","December"}; 
	                                                                            
	int mm, dd, yyyy, year = 0;
	
	cout << "This program will display date and convert number of month to string" << endl;
	//Prompts user for input
    cout << "Enter month in the form of mm: ";
    cin >> mm;//Get month from input
  if( mm < 1 || mm > 12 )// Validate to see if input for month is valid
		{
         cout << "INVALID month: Please try again." << endl;
		 cin.get();
		 system ("pause");
		 exit (1);
         }
	cout << "Enter day in the form of dd: ";
	cin >> dd;//Get day from input
  if( dd < 1 || dd > months[dd-1] )// Validate to see if input for day is valid
		{
         cout << "INVALID day: Please try again." << endl;
		 cin.get();
		 system ("pause");
		 exit (1);
		}
	cout << "Enter year in the …
gazoo 0 Light Poster

I see and very sorry,

Highlighted I have change the code as reconmended, I have error: [error]
error LNK2019: unresolved external symbol "bool __cdecl leapyear(int)" (?leapyear@@YA_NH@Z) referenced in function _main
[error]

#include <iostream>
#include <string>
#include <math.h>

using namespace std;

//Declare the function
bool leapyear(int year);
	
struct // struct declaration
{
	int Month;
	int Day;
	int Year;
	
}date;

int main()
{
		      				
	// Intialize Array For Number Of Days In Each Month 
	int months[12]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month
	//Initialize array for number of month in the year
	const unsigned int string_month = 12;
	string arr[string_month] = {"January","february","March","April","May","June","July","August","September","October","November","December"}; 
	                                                                            
	int mm, dd, yyyy, year = 0;
	
	cout << "This program will display date and convert number of month to string" << endl;
	//Prompts user for input
    cout << "Enter month in the form of mm: ";
    cin >> mm;//Get month from input
	cout << "Enter day in the form of dd: ";
	cin >> dd;//Get day from input
	cout << "Enter year in the form of yyyy: ";
	cin >> yyyy;//Get year from input
	cin.get();

    if( mm < 1 || mm > 12 )// Validate to see if input for month is valid
		{
         cout << "INVALID month: Please try again." << endl;
		 cin.get();
		 exit (1);
         }
         
    if( dd < 1 || dd > months[dd-1] )// Validate to see if input for day is valid
		{
         cout << "INVALID day: Please try again." << endl;
		 cin.get();
		 exit (1);
		}

	if(leapyear(year))

		cout << "is a …
gazoo 0 Light Poster

Sorry what is that mean??

you double posted the code.

gazoo 0 Light Poster

Hi Ancient Dragon;

I changes the line highlighted and I'm not sure if I need semicolon after the function :bool leapyear( int year) ??? it seem to complained :error C2143: syntax error : missing ';' before '<class-head>', maybe I have more then one return??. Please explain what is this line does: return (year % 4) == 0 ? true : false;. I understand return(year%4)==0, but nerver see the ( ? ) and ( true:fal; ) before. Thank in advance.

#include <iostream>
#include <string>
#include <math.h>

using namespace std;

//Declare the function
bool leapyear(int year)
	
struct // struct declaration
{#include <iostream>
#include <string>
#include <math.h>

using namespace std;

//Declare the function
bool leapyear(int year)
	
struct // struct declaration
{ <<<<<<<<<<<< error C2143: syntax error : missing ';' before '<class-head>'
	int Month;
	int Day;
	int Year;
	
}date;

int main()
{
		      				
	// Intialize Array For Number Of Days In Each Month 
	int months[12]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month
	//Initialize array for number of month in the year
	const unsigned int string_month = 12;
	string arr[string_month] = {"January","february","March","April","May","June","July","August","September","October","November","December"}; 
	                                                                            
	int mm, dd, yyyy, year = 0;
	
	cout << "This program will display date and convert number of month to string" << endl;
	//Prompts user for input
    cout << "Enter month in the form of mm: ";
    cin >> mm;//Get month from input
	cout << "Enter day in the form of dd: ";
	cin >> dd;//Get day from input
	cout << "Enter year in the form of yyyy: ";
	cin …
gazoo 0 Light Poster

Hello Ancient Dragon,

Want to thank you very much for all your help, I was born in the year of dragon I guess I'm very slow, I have added the lines you have reconmended and so far so good. One warning related to "lpyr" :warning C4101: 'lpyr' : unreferenced local variable

#include <iostream>
#include <string>
#include <math.h>

using namespace std;

//Declare the function
bool leapyear(int lpyr);
	
struct // struct declaration
{
	int Month;
	int Day;
	int Year;
	
}date;

int main()
{
		      				
	// Intialize Array For Number Of Days In Each Month 
	int months[12]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month
	//Initialize array for number of month in the year
	const unsigned int string_month = 12;
	string arr[string_month] = {"January","february","March","April","May","June","July","August","September","October","November","December"}; 
	                                                                            
	int mm, dd, yyyy, lpyr, lp_ck = 0;
	
	cout << "This program will display date and convert number of month to string" << endl;
	//Prompts user for input
    cout << "Enter month in the form of mm: ";
    cin >> mm;//Get month from input
	cout << "Enter day in the form of dd: ";
	cin >> dd;//Get day from input
	cout << "Enter year in the form of yyyy: ";
	cin >> yyyy;//Get year from input
	cin.get();

    if( mm < 1 || mm > 12 )// Validate to see if input for month is valid
		{
         cout << "INVALID month: Please try again." << endl;
		 cin.get();
		 exit (1);
         }
         
    if( dd < 1 || dd > months[dd-1] )// Validate to see if input for day is valid …
gazoo 0 Light Poster

Hello Everyone,

I'm new to the forum, currentely I'm taking the basic C++ class and struggle through, it has been over 20 years since write any codes. I have some trouble with the code below, it work fine if I don't bother to check for leap year, but the assignmnet required check the for leap year divisible by 4 then day range from 1-29 and year is February. I put the part for leapyear checker, then it did not work, can anyone help see what I did wrong?? Part that I highlighted has been added then the code crash, please help.

#include <iostream>
#include <string>
#include <math.h>

using namespace std;

//Declare the function
bool leapyear(int lpyr);
	
struct // struct declaration
{
	int Month;
	int Day;
	int Year;
	
}date;

int main()
{
		      				
	// Intialize Array For Number Of Days In Each Month 
	int months[12]= {31,29,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month
	//Initialize array for number of month in the year
	const unsigned int string_month = 12;
	string arr[string_month] = {"January","february","March","April","May","June","July","August","September","October","November","December"}; 
	                                                                            
	int mm, dd, yyyy, lpyr = 0;
	
	cout << "This program will display date and convert number of month to string" << endl;
	//Prompts user for input
    cout << "Enter month in the form of mm: ";
    cin >> mm;//Get month from input
	cout << "Enter day in the form of dd: ";
	cin >> dd;//Get day from input
	cout << "Enter year in the form of yyyy: ";
	cin >> yyyy;//Get year from input
	cin.get();

    if( …