NOTE: This is for homework, I just want to know why i get the messed up print, not the finished program.
#include <stdio.h>
char get_band( int band_number, char band_color[] );
void get_resistance( int resist, int power );
int main()
{
int resist;
int power;
get_resistance(resist, power );
}
void get_resistance( int resist, int power )
{
int band_number;
char band_color[3];
char color[3];
get_band( band_number, band_color );
printf("%s", band_color);
}
char get_band( int band_number, char band_color[] )
{
int x;
x=0;
while (x < 3)
{
printf("Which band would you like to select? (1-3)\nDo not select one you have selected prior!\t");
scanf("%d", &band_number);
if (band_number = 1)
{
printf("What color would you like to assign here?\t");
scanf("%s", &band_color[0]);
x++;
}
else if (band_number = 2)
{
printf("What color would you like to assign here?\t");
scanf("%s", &band_color[1]);
x++;
}
else if (band_number = 3)
{
printf("What color would you like to assign here?\t");
scanf("%s", &band_color[2]);
x++;
}
}
return (*band_color);
}
So when I run it, I get no errors or warnings, but what I do get is the last color I enter. For example, I enter green, blue, yellow, in that order. I will get yellow printed back. Regardless of what order I use for the numbers, I always get back the very last color entered.