I've written a code but it doesn't run!
I can't find the problem and the Error is :
Declaration Syntax Error
will anyone help me?! :)

#include<iostream.h>
void hi(void);
void name(void);
int main()
{
	 int m;
	 cout<<"Enter one of numbers below:\n"<<"1.Hi\n"<<"2.Name:";
	 cin>>m;
	 switch (m)
			{
			 case 1: hi();
				break;
			 case 2: name();
				break;
			 }

	 return 0;
}
void hi(void)
{
  int a,b,c;

  for(a=1;a<8;a++)
	  {
		if(a==4)
		  {
			for(b=1;b<9;b++)
				{
				 if(b==6 || b==7)
				   cout<<" ";
				 else
				   cout<<"*";
				 }
			}
		else
		  for(c=1;c<9;c++)
			  {
				if(c==1||c==5||c==8)
					cout<<"*";
				else
					cout<<" ";
				}
		  cout<<"\n";

	  }
}
void name(void)
{
	int d,e,f,g,h,i,j,k;
		for(d=1;d<8;d++)
		{
		switch (d){
			 case 1:
			 {
			 for(e=1;e<30;e++)
			 {
 if(e==1||e==2||e==3||e==4||e==5||e==7||e==11||e==15||e==19||e==21||e==22||e==23||e==29)
							               cout<<"*";								                             else
                            cout<<" ";
               }
	  cout<<"\n";
	  break;
           }
	  case 2:
	 {
	 for(f=1;f<31;f++)
	  {
	if(f==1||f==7||f==11||f==14||f==16||f==19||f==21||f==24||f==28||f==30)
           cout<<"*";
	 else
	   cout<<" ";
	  }
	 cout<<"\n";
	 break;
         }
	 case 3:
	 {
	for(g=1;g<32;g++)
	{
	if(g==1||g==7||g==13||g==17||g==19||g==21||g==25||g==27||g==31)
	  cout<<"*";
	 else
	   cout<<" ";
	}
	 cout<<"\n";
	  break;
	}

	 case 4:
         {
	for(h=1;h<32;h++)
	{
	if(h==6||h==12||h==18||h==20||h==22||h==23||h==24||h==26)
	  cout<<" ";
	else
	  cout<<"*";
	}
	cout<<"\n";
	break;
	}
	 case 5:
         {
	  for(i=1;i<32;i++)
	  {
   if(i==5||i==7||i==11||i==13||i==17||i==19||i==21||i==25||i==27||i==31)
	cout<<"*";
	 else
	cout<<" ";
          }
	  cout<<"\n";
	  break;
	}
	 case 6:
         {
	  for(j=1;j<32;j++)
	   {
           if(j==5||j==7||j==11||j==13||j==17||j==19||j==21||j==24||j==27||j==31)
             cout<<"*";
	   else
	    cout<<" ";
           } 
	  cout<<"\n";
	  break;
	}
	 case 7:
         {
	for(k=1;k<32;k++)
	 {
	if(k==1||k==2||k==3||k==4||k==5||k==7||k==11||k==13||k==17||k==19||k==21||k==22||k==23||k==27||k==31)
         	cout<<"*";
	 else
		cout<<" ";
	}
	cout<<"\n";
	break;
	}
  }
 }
}

Recommended Answers

All 5 Replies

#include<iostream.h>
void hi(void)
void name(void)
int main()
{

First of all, you should include <iostream>, not <iostream.h>
Secondly, you should tell us in what line the error is.. or at least copy/paste the exact error.
But I tried to compile your code and the error is in the 3 lines that I pasted above: Now if you look at just those lines, what do you think is missing?

Hi Shaida :-)

When declaring the functions 'hi' and 'name' at the top, you have to end the statement with a ';'.

Like this:

#include<iostream.h>
void hi(void);
void name(void);
int main()
{
...

Also add std namespace :

#include<iostream.h>
void hi(void);
void name(void);
using namespace std;
int main()
{
...
}

Otherwise you get errors like "cin" not found, and so on.

Hi Shaida :-)

When declaring the functions 'hi' and 'name' at the top, you have to end the statement with a ';'.

Like this:

#include<iostream.h>
void hi(void);
void name(void);
int main()
{
...

thanks
I did this; but the error is still in line 3

Also add std namespace :

#include<iostream.h>
void hi(void);
void name(void);
using namespace std;
int main()
{
...
}

Otherwise you get errors like "cin" not found, and so on.

I have an old compiler, so I should write

#include<iostream.h>

instead of #include<iostream> and it doesn't need "Ysing namespace...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.