array of strings

I'm having trouble elements from an array and then converting them to its correct code. this assignment asks to use functional decomposition to prompt user for the color of each band then calculates the value of the resistor.
example
color band1: >green
color band2: >blue
color band3: >black
color of multiplier: >orange
color of tolerance: > silver

this resistor has 560000 ohms with 10% tolerance

end example

this code is not complete. still working on the first three colors but when I run the program I get an undefined reference error. can anyone help and distinguish what I'm doing wrong.

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

void getColorCode(string[], string );

const int BC_CODE = 10;
const int MC_CODE = 12;
const int TC_CODE = 4;

int main()
{
string band1, band2, band3, input;
string BAND_COLOR_CODE[BC_CODE] = { "black", "brown", "red", "orange", "yellow",
"green", "blue", "violet", "grey", "white" };

string MULTIPLIER_COLOR_CODE[MC_CODE] = { "black", "brown", "red", "orange", "yellow",
"green", "blue", "violet", "grey", "white",
"gold", "silver" };

string TOLERANCE_COLOR_CODE[TC_CODE] = { "brown", "red", "gold", "silver" };

cout << "Enter color for band 1: ";
getline(cin, band1);
getColorCode(BAND_COLOR_CODE, band1);

cout << "Enter color for band 2: ";
getline(cin, band2);
getColorCode(BAND_COLOR_CODE, band2);

cout << "Enter color for band 3: ";
getline(cin, band3);
getColorCode(BAND_COLOR_CODE, band3);


cout << band1 << band2 << band3;
return 0;
}

void getColor(string BAND_COLOR_CODE[], string choice)
{
string code;
if (choice == "black")
code == "0";
else if(choice == "brown")
code == "1";
else if(choice == "red")
code == "2";
else if(choice == "orange")
code == "3";
else if(choice == "yellow")
code == "4";
else if(choice == "green")
code == "5";
else if(choice == "blue")
code == "6";
else if(choice == "violet")
code == "7";
else if(choice == "grey")
code == "8";
else if(choice == "white")
code == "9";

}


btw the first three bands represent the first string array the next would be the second and last for the third
thankyou
The prototype getColorCode(...) does not match the implementation getColor(...).

By the way: getColor(...) does nothing. What is this function supposed to do?
OP: if you want to read off the color codes for any given color you may wish to use a std::map with some error checking for non-existent colors. Here is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
#include <map>

using namespace std;

map<string, int> band_cc{ {"black", 0}, {"brown", 1}, {"red", 2}, {"orange", 3} , {"yellow", 4}, {"green", 5},
    {"blue", 6}, {"violet", 7} ,{"grey", 8}, {"white", 9}};

int main()
{
    cout << "Enter color for band 1: \n";
    string color;
    cin >> color;
    if(band_cc.find(color) != band_cc.end())
    {
        cout << "Code for: " << color << " is: " << band_cc.find(color) -> second << '\n';
    }
    else
    {
        cout << "Color not found \n";
    }
}


And if you haven't seen this thread already, it might be of some interest: http://www.cplusplus.com/forum/beginner/204169/
Topic archived. No new replies allowed.