program needs to loop 10 times, can not figure out where to place for loop

#include <iostream>
#include <stdlib.h>
#include <iomanip>

using namespace std;

class myInt// setting a Class

{

private:

int value;

public:

myInt()//default constructor

{

value=0;

}

myInt (int value)//default constructor

{

setInt(value);

}
void setInt (int value)//set method
{

if(value<0)
value = abs(value);
this->value = value;

}

void print()//print method

{
cout << value;
}

int getInt()//get method

{
return value;
}


int sumDigits()//method to sum the digits of the number given
{
int sum,digit;
sum=0;
int temp=value;
while (value > 0 )
{
digit= value % 10;
sum= sum+digit;
value=value/10;
}
value=temp;
return sum;
}


int Reverse() // This Function reverses the numbers within the integer.
{
int reversed, temp;
temp=value;
reversed=0;
while (value!=0)
{
reversed=reversed*10;
reversed=reversed+value%10;
value=value/10;
}
value=temp;
return reversed;
}


int oddCount() // This Function counts the number of odd integers in the number then displays the value.
{
int odd, num, temp;
odd=0;
temp=value;
while(value>0)
{
num= value%10;
if(num % 2 == 1)
odd++;
value=value/10;
}
value=temp;
return odd;
}


int evenCount()// Counts the number of even integers in the number then displays the value.
{
int even,num,temp;
even=0;
temp=value;
while (value >0)
{
num= value%10;
if(num %2 == 0)
even++;
value=value/10;
}
value=temp;
return even;
}


int zeroCount()// Counts the number of zeros in the integer and then displays the value.
{
int zero,num,temp;
zero=0;
temp=value;
while(value>0)
{
num= value%10;
if(num == 0)
zero++;
value=value/10;
}
value=temp;
return zero;
}
};


int main()
{
srand(815);//seed of random number is 815
myInt myIntobject(rand()%10000);
int runtime;
do
{
cout <<" The number is " << myIntobject.getInt()<< endl;
cout <<" ---------------------------------------------------- " <<endl;
cout << " Adding the digits result " <<setw(26)<<myIntobject.sumDigits()<<endl;
cout <<" Reversing the digits result " << setw(23)<<myIntobject.Reverse()<<endl<<endl;
cout <<" Odd digits " <<setw(40)<< myIntobject.oddCount()<<endl;
cout <<" Even digits " <<setw(39)<< myIntobject.evenCount()<<endl;
cout <<" Zeroes " <<setw(44) << myIntobject.zeroCount()<<endl<<endl;
runtime ++;
}while (runtime==10);
return 0;
}


Last edited on
its my understanding the for loop should be placed at the beginning of the program but after your declaration

it should look something like this

for ( int i; i<10;i++)
{

all of your code in the middle

}


the i<10, will allow the program to only run 10 times
Topic archived. No new replies allowed.