Recursion function

Hello friends,
I am having troubles with writing a recursion function, that returns a boolean, that finds the length of an integer. For example, if the integer entered is 6, it would return being odd. If the integer entered is 13, it would be even. Its the amount of digits in the integer. The function is given an integer parameter, and it should return a boolean value.
This is what I have so far...

THE FUNCTION I NEED HELP WITH IS CALLED "evenWidth".

Do i have to use mod or division. Any help would be great, Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
 //  workerBee.cpp

#include "workerBee.h"
#include "Tools.h"

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

const double MAX_ERROR = 0.0000000001;

void workerBees(void)
{
    do
    {
        workerBee();
        
    }while (getBool("Test another? "));
}

void workerBee(void)
{
    int userSelection = getBoundedInt
    ("Select test: 1-printMultiple, 2-printSequence, 3-evenWidth, 4-squareRoot: ", 1, 4);
    
    switch( userSelection )
    {
        case 1:
        {
            int userNum = getPositiveInt("How many? ");
            bool userChoice = getBool("All on one line? ");
            string testingString = getString("What do you want to print? ");
            
            printMultiple( userNum, userChoice, testingString );
            
            cout << endl;
        }
            break;
        case 2:
        {
            int userNum = getPositiveInt("Enter sequence limit: ");
            printSequence( userNum );
            
            cout << endl;
        }
            break;
        case 3:
        {
            int userNum = getPositiveInt("Enter the length of a width: ");
            evenWidth( userNum );
            
            if ( evenWidth( userNum ) )
            {
                cout << "Your width, " << userNum << ", is even." << endl;
            }
            
            else cout << "Your width, " << userNum << ", is odd." << endl;
        }
            break;
        case 4:
        {
            int userNum = getPositiveInt("Enter a number: ");
            squareRoot( userNum );
            
            cout.precision(10);
            cout << "The square root is " << userNum << "." << endl;
        }
            break;
    }
}

void printSequence( int count )
{
    if ( count >= 0)
    {
        cout << count << endl;
        printSequence( count - 1 );
    }
}

void printMultiple( int count, bool onSameLine, string userWord )
{
    if ( onSameLine )
    {
        if ( count >= 1)
        {
            cout << userWord << " ";
            printMultiple( count - 1, onSameLine, userWord);
        }
    }
    
    else
    {
        if ( count >= 1)
        {
            cout << userWord << " " << endl;
            printMultiple( count - 1, onSameLine, userWord);
        }

    }
}

bool evenWidth( int count )
{
    bool isEven;
    
    if ( isEven )
    {
        
    }
    else return false;
    
    return true;
    
}

double squareRoot( int count )
{
    double guess = 1.0;
    double newGuess = ( count/guess + guess )/ 2.0;
    double difference = ( newGuess - guess );
    
   
    if ( difference <= MAX_ERROR )
    {
        return  squareRoot( count-1 );
    }
    
    return guess = newGuess;
}









bump........
Topic archived. No new replies allowed.