# Want count past 9 should count to 999

In this program I need to use 3 nested for loops to split up a number I enter and count up to that number. Ex: I enter 123 suppose to count like 000
001
...
#include
using namespace std;

int main()
{

int posinta=0;
int repeat=0;
int posinta2=0;

do{
cout << "Welcome to the counting program.
";

cout << "please enter a positive integer "<< "between 0 and 999.
"<< "?";
cin >> posinta;

while((posinta<0)||(posinta>999)){
cout << "You have not entered the correct integer "<< "in the range of 0 to 999.
";
"<< "?";
cin >> posinta;
}

cout << " you have entered the correct number.
";

int posintb=0,posintc=0,posintd=0; //declares posintb in hundreads, posintc in tens, and posintd in ones

posintd=(posinta%10);//takes the int in ones place and put into posintd
posinta2=(posinta/10);//braking down posinta to tens place
posintc=(posinta2%10); //takes the int in tens place and put into c
posintb=(posinta/100); //takes the int in hundreads place and put into b

int e,f,g; //declares int e,f,and g

for(e=0;e<=9;e++){ //increments hundreads place by one

for(f=0;f<=9;f++){ //increments tens place by one

for(g=0;g<=9;g++){ //increments ones place by one
cout<<e<<f<<g<<endl;

if((e==posintb)&&(f==posintc)&&(g==posintd))break;

}break;
}break;
}

cout<< "do you want to count again?"<<" enter 0 for no and 1 for yes"<<endl;
cin>>repeat;
}while((!repeat==0)||(repeat==1));// determines if user wants to count again or not.
cout<<"see you later"<<endl;

return 0;

}

• hi,

i guess the break statements of the two outer for loops are incorrect.
u can change it as shown.
---------------------------------------------------
int e,f,g; //declares int e,f,and g

int flag=0;
for(e=0;e<=9;e++)
{ //increments hundreads place by one

for(f=0;f<=9;f++)
{ //increments tens place by one

for(g=0;g<=9;g++)
{ //increments ones place by one
cout<<e<<f<<g<<endl;
if((e==posintb)&&(f==posintc)&&(g==posintd))
{
flag=1;
break;

}

}
if(flag)
break;
}
if(flag)
break;
}

----------------------------------------------------------------
: In this program I need to use 3 nested for loops to split up a number I enter and count up to that number. Ex: I enter 123 suppose to count like 000
: 001
: ...
: #include <iostream>
: using namespace std;
:
: int main()
: {
:
: int posinta=0;
: int repeat=0;
: int posinta2=0;
:
: do{
: cout << "Welcome to the counting program.
";
:
: cout << "please enter a positive integer "<< "between 0 and 999.
"<< "?";
: cin >> posinta;
:
: while((posinta<0)||(posinta>999)){
: cout << "You have not entered the correct integer "<< "in the range of 0 to 999.
";
: cout << "please try again.
"<< "?";
: cin >> posinta;
: }
:
: cout << " you have entered the correct number.
";
:
:
:
: int posintb=0,posintc=0,posintd=0; //declares posintb in hundreads, posintc in tens, and posintd in ones
:
: posintd=(posinta%10);//takes the int in ones place and put into posintd
: posinta2=(posinta/10);//braking down posinta to tens place
: posintc=(posinta2%10); //takes the int in tens place and put into c
: posintb=(posinta/100); //takes the int in hundreads place and put into b
:
:
:
: int e,f,g; //declares int e,f,and g
:
:
: for(e=0;e<=9;e++){ //increments hundreads place by one
:
: for(f=0;f<=9;f++){ //increments tens place by one
:
: for(g=0;g<=9;g++){ //increments ones place by one
: cout<<e<<f<<g<<endl;
:
:
: if((e==posintb)&&(f==posintc)&&(g==posintd))break;
:
: }break;
: }break;
: }
:
:
:
:
: cout<< "do you want to count again?"<<" enter 0 for no and 1 for yes"<<endl;
: cin>>repeat;
: }while((!repeat==0)||(repeat==1));// determines if user wants to count again or not.
: cout<<"see you later"<<endl;
:
:
:
:
:
: return 0;
:
: }
:
:
:
:
:
:
:
: