#include<iostream>

using namespace std;

int main()

{

int *number=new int[1000];
int c=0;


int i=0;

cout<<"Enter no sir\n";

cin>>number[i];



while(number[i]>0)
{
number[i]/=10;

c++;

}

cout<<"\n\n"<<"TOTAL NO OF DIGITS = "<<c;

delete[]number;

return 0;

}

The problem is that if i ENTER an integer that iss greater than or Equal to 10 digits ...this code doesnot tell that u entered a 10-digit integer...i think it had something to do with stack memory issue as it is limited...so thats why i allocated memory using dynamic memory allocation..but still the problem remained unsolved ...so plz help me in this ..with few explanations concerning the problem as well

with thanks
:)

First, I think you wanted to create a single int not an array. Second, it doesnt matter if you create it dynamically, an int cant hold a number that big, use type long.

could u plz post the modified code over here..coz i have already tried long data type,...it doesnt work

char ch;
cin>>ch;
if(ch=='SU')
{
run this code..etc
}
but if i enter ch==SU ..if condition doesnot get to true and code doesnt run,,,coz single digit can be stored in character..if use char array..even then conditinal IF statement doesent run..whats the prob ?? :(
char ch;
cin>>ch;
if(ch=='SU')
{
run this code..etc
}

first : char only hold one character
second : '' only work on single character but "" for string(multiple characters)
third : the built in type

char

do not support "=="

int number = 10;
  size_t accumulate = 0;

  while(number > 0)
  {
    number /= 10;
    //++accumulate would be a better choice, since it would not produce temporary object for some types
    //although for primitive type ++c or c++ is trivial, but using prefix ++ is a good habit
    ++accumulate;                   
  }

  std::cout<<"\n\nTOTAL NO OF DIGITS = "<<accumulate;

  //you could use numeric_limits to check the upper bound of the primitive types
  //the header file is <limits>
  std::cout<<std::numeric_limits<int>::max()<<std::endl; 
  std::cout<<std::numeric_limits<int>::min()<<std::endl;

On most modern compilers, a long is a 32-bit integer value, the same as an int. If your compiler and/or system support it, I would consider a long long if you want a value that has more than 10 digits. With this type, you would now be limited to 19 digits (unsigned would be 20).

If you want more than that, you'll have to use character arrays/strings or find a special large number library.

#include<iostream>

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

int main()

{

int year ,month,i,c,c1;

char day;

cout<<"Enter The Year\n";

cin>>year;

cout<<"Enter the Month \n";

cin>>month;

for(;month<=12;month++)
{


// identifying whether its leap year or not...

if(year%4==0 || ((year%100==0)&&(year%400)) )
{
	 c=1;

}

cout<<"\nMonth:"<<month<<"\n\n";

cout<<"Enter the day of first date of month\n";

cin>>day;

cout<<"S"<<setw(6)<<"M"<<setw(6)<<"T"<<setw(6)<<"W"<<setw(6)<<"t"<<setw(6)<<"F"<<setw(6)<<"s"<<endl;

if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
	 c1=31;

}
else if((month==2)&&(c==1))
{
	c1=29;
}
else if(month==2&&c!=1)
{
	c1=28;
}
else
{
	c1=30;

}

for(i=1;i<=c1;i++)
{
	
if(day=='S')
{

	cout<<i<<setw(6);

if(i==7||i==14||i==21||i==28)
{
	cout<<endl;
	cout<<setw(0);

}
}
else if(day=='M')
{
	if(i==1)
	{
		cout<<setw(7);
	cout<<i;
	}
	else if(i==7||i==14||i==21||i==28)
	{
			

		cout<<endl<<setw(0)<<i;
	}
	else
	{
		cout<<setw(6)<<i;
	}


if(i==6||i==13||i==20||i==27)
{
	cout<<endl;
	cout<<setw(0);

}

}
else if(day=='T')
{

if(i==1)
	{
		cout<<setw(13);
	cout<<i;
	}
	else if(i==6||i==13||i==20||i==27)
	{
			

		cout<<endl<<setw(0)<<i;
	}
	else
	{
		cout<<setw(6)<<i;
	}


if(i==5||i==12||i==19||i==26)
{
	cout<<endl;
	cout<<setw(0);

}
}
else if(day=='W')
{
	if(i==1)
	{
		cout<<setw(19);
	cout<<i;
	}
	else if(i==5||i==12||i==19||i==26)
	{
			

		cout<<endl<<setw(0)<<i;
	}
	else
	{
		cout<<setw(6)<<i;
	}
if(i==4||i==11||i==18||i==25)
{
	cout<<endl;
	cout<<setw(0);

}
}
else if(day=='t')
{
	if(i==1)
	{
		cout<<setw(25);
	cout<<i;
	}
	else if(i==4||i==11||i==18||i==25)
	{
			

		cout<<endl<<setw(0)<<i;
	}
	else
	{
		cout<<setw(6)<<i;
	}

if(i==3||i==10||i==17||i==24||i==31)
{
	cout<<endl;
	cout<<setw(0);

}
}
else if(day=='F')
{
	if(i==1)
	{
		cout<<setw(31);
	cout<<i;
	}
	else if(i==3||i==10||i==17||i==24||i==31)
	{
			

		cout<<endl<<setw(0)<<i;
	}
	else
	{
		cout<<setw(6)<<i;
	}

if(i==2||i==9||i==16||i==23||i==30)
{
	cout<<endl;
	cout<<setw(0);

}
}
else if(day=='s')
{
	if(i==1)
	{
		cout<<setw(37);
	cout<<i;
	}
	else if(i==2||i==9||i==16||i==23||i==30)
	{
			

		cout<<endl<<setw(0)<<i;
	}
	else
	{
		cout<<setw(6)<<i;
	}

if(i==1||i==8||i==15||i==22||i==29)
{
	cout<<endl;
	cout<<setw(0);

}
}

}

cout<<"\n\n\n\n";

}

return 0;

}

this program displays a calender..it asks for year ..then month then day on which first date falls then shows calender..then loop runts till months=12 ..BUT problem is THAT...I WANT ke if i enter 2011 march (1st date on MONDAY) then it should print calender of MARCH APRIL.....DECEMBER itself...it shouldnt prompt for starting dated of all upcoming MONTHS>>>>>PLZ HELP IN THIS CODE....and post my code with changes...

plz reply :(

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.