Error message saying pow is ambiguous?!?! Any suggestions

I have a rough time with this code. Trying to use the formula at the bottom. It has a problem with pow(10,Band4). It says "call to pow is ambiguous" on line 141.

This is a poorly constructed switch but it's what i have for now. Could someone at least tell me why pow is not working. Appreciate any advice.


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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include <cstring>
#include <string>
#include <stdio.h> 
#include <cmath>
#include <cstdlib>
#include <iomanip> 
using namespace std;
int main()
{
    
    // Define a new datatype R_Colors and
    // the values associated with R_Colors.
    
    enum R_Colors {Black, Brown, Red, Orange, Yellow,
                   Green, Blue, Purple, Gray, White,
                   Gold, Silver, None};
    
    R_Colors Band1, Band2, Band3, Band4;
    char userChoice;
    int Value;
    string a;
    do {
        
    cout << "\t\t\tResistor's Colors\n"
         << "\tEnter a) Step1: Intialize Band1\n"
         << "\tEnter b) Step2: Intialize Band2\n"
         << "\tEnter c) Step3: Intialize Band3\n"
         << "\tEnter d) Step4: Intialize Band4\n"
         << "\tEnter e) if all steps are complete\n"
         << "\tEnter f) to quit program\n";
    cout << "Enter your choice: " << endl;
        
     cin >> userChoice;
    
    switch (userChoice)
        {
            case 'a':
            cout << "Enter the color";
            cin >> a;
            if (a == "Black")
                Band1 = Green;
            else if(a == "Brown")
                Band1 = Brown;
            else if(a == "Red")
                Band1 = Red;
            else if(a == "Orange")
                Band1 = Orange;
            else if(a == "Yellow")
                Band1 = Yellow;
            else if(a == "Blue")
                Band1 = Blue;
            else if(a == "Purple")
                Band1 = Purple;
            else if(a == "Gray")
                Band1 = Gray;
            else
                Band1 = White;
                //cout << Band1 << endl;
            break;
            
            case 'b':
            cout << "Enter the color";
            cin >> a;
            if (a == "Black")
                Band2 = Green;
            else if(a == "Brown")
                Band2 = Brown;
            else if(a == "Red")
                Band2 = Red;
            else if(a == "Orange")
                Band2 = Orange;
            else if(a == "Yellow")
                Band2 = Yellow;
            else if(a == "Blue")
                Band2 = Blue;
            else if(a == "Purple")
                Band2 = Purple;
            else if(a == "Gray")
                Band2 = Gray;
            else
                Band2 = White;
                //cout << Band2 << endl;
            break;
            
            case 'c':
            cout << "Enter the color";
            cin >> a;
            if (a == "Black")
                Band3 = Green;
            else if(a == "Brown")
                Band3 = Brown;
            else if(a == "Red")
                Band3 = Red;
            else if(a == "Orange")
                Band3 = Orange;
            else if(a == "Yellow")
                Band3 = Yellow;
            else if(a == "Blue")
                Band3 = Blue;
            else if(a == "Purple")
                Band3 = Purple;
            else if(a == "Gray")
                Band3 = Gray;
            else
                Band3 = White;
                //cout << Band3 << endl;
            break;
            
            case 'd':
            cout << "Enter the color";
            cin >> a;
            if (a == "Black")
                Band4 = Green;
            else if(a == "Brown")
                Band4 = Brown;
            else if(a == "Red")
                Band4 = Red;
            else if(a == "Orange")
                Band4 = Orange;
            else if(a == "Yellow")
                Band4 = Yellow;
            else if(a == "Blue")
                Band4 = Blue;
            else if(a == "Purple")
                Band4 = Purple;
            else if(a == "Gray")
                Band4 = Gray;
            else
                Band4 = White;
                //cout << Band4 << endl;
            break;
            
            case 'e':
            cout << "All Bands have been initialized" << endl;
                cout << "Band1 is equal to = " << Band1 << endl;
                cout << "Band2 is equal to = " << Band2 << endl;
                cout << "Band3 is equal to = " << Band3 << endl;
                cout << "Band4 is equal to = " << Band4 << endl;
                                
                Value = ((Band1*10)+Band2)*pow(10,Band3);
                
                cout << "The Resistors Value is " << Value << endl;
                
            break;
            
            case 'f':
            cout << "Quitting Program" << endl;
            return 0;
        }
    }while (true);
    
   
    
    return 0;
}

Last edited on
pow() only takes double and float values as arguments. Try typecasting it:

Value = ((Band1*10)+Band2)*pow(10,(float)Band3);
Using static variables like Band1, Band2, etc., is going to make it much harder to convert to 5 and 6 band resistors later on. That's why I suggested using an array, where numOfBands - 1 is going to be your tolerance, and numOfBands - 2 is going to be your multiplied. Using that information, it's easy to generate any number of resistor values (hoping that the only difference between 4-6 band resistors is extra primary numbers).

Also, instead of casting Band3 to a float, it's typically easier to cast 10 to 10.0 or 10.0f.

Please note that it's courteous to keep one thread per topic. I've noticed you've been creating new threads every time you have a question, but all you need to do is reply to the current thread, even if it's a different issue. Try to keep new threads for completely unrelated issues, as in you're working on a separate program, want to know an algorithm for a sort function, or just want to learn new topics involving electrical engineering.
Has anyone suggested having a function for getting the colour? Lines 39 - 60 are repeated 4 times, with the only difference being the Band number - which leads to Volatile Pulse's idea of using an array or vector.

If you see that you have lots of repeated code, then you should look for other ways of doing things.

Instead of using an enum, it would be easier to just set the values to double. Also you have no error checking on the spelling / case of the user input, so it would be better to get input from an integer choice processed with a switch. This would avoid the need to set Black to Green because Black is zero in the enum. And the value could be set via a cast to double without a load of if else clauses.

If you use these ideas together then this will tidy up your code considerably.

I also dislike the idea of an infinite do loop.

EDIT: I have just seen cire's solution in the other thread. This is why duplicate threads are annoying.
Last edited on
Topic archived. No new replies allowed.