Hello, I'm really new to C++ and this forum, but I have read the "rules" regarding homework and I'm just looking for some guidance. I need to create a function that asks for the user to input an integer, finds the number of digits and digits at position, sum digits, average digits and find max and min from the number. What I am really trying to create is the finddigitsatpos iton function. The rest I have either done or understand.
So, the following is what I have...keep in mind the user will have inputted an integer:
[CODE=cpp]int FindDigitAtPosi tion ( int x, double counter )
{
for ( i = 1; i <= counter; ++i )
{
x = x % 10;
if ( max <= x )
{
max = x;
}
else
{
max = max;
}
cout << x << ":" << max <<endl;
}
return max;
}[/CODE]
What I cannot seem to understand is the % and loops. What I am wanting to do is create a loop that will loop as many times as my counter (which was a part of my findnumberofdig its function) tell my loop to do so. This part work. The next thing ....I think is that I am wanting to catch the remainder of x % 10 on each loop and compare it to max (which is initialize to 0 ) and keep the larger number. What I know isn't happening is my x only captures the initial remainder from the last digit. Any suggestions???
Thanks so much....
Kay
So, the following is what I have...keep in mind the user will have inputted an integer:
[CODE=cpp]int FindDigitAtPosi tion ( int x, double counter )
{
for ( i = 1; i <= counter; ++i )
{
x = x % 10;
if ( max <= x )
{
max = x;
}
else
{
max = max;
}
cout << x << ":" << max <<endl;
}
return max;
}[/CODE]
What I cannot seem to understand is the % and loops. What I am wanting to do is create a loop that will loop as many times as my counter (which was a part of my findnumberofdig its function) tell my loop to do so. This part work. The next thing ....I think is that I am wanting to catch the remainder of x % 10 on each loop and compare it to max (which is initialize to 0 ) and keep the larger number. What I know isn't happening is my x only captures the initial remainder from the last digit. Any suggestions???
Thanks so much....
Kay
Comment