Text conversion to an integer

0 Randy Taylor · September 28, 2015
Hello everyone. I'm trying to write a Program that calculates the color code of a resistor.
 And I'm having a problem  with when you write the color at the prompt, say brown,
it is converted to an integer like number 1. Thanks for any help given.

Post a Reply

Replies

Oldest  Newest  Rating
0 Randy Taylor · September 29, 2015
Thanks for the help. I was thinking along those lines, but wasn't sure how  to it implement it.
Once again I thank you.
0 Randy Taylor · September 29, 2015
  Ok I've tried that. But I'm not getting it to change to the next value.  Here's the code I've tried.
Thank you for any help.

#include
#include
int main()
{
char * color_string1 = "brown";
char * color_string2 = "black";
char * color_string3 = "yellow";
int color_code = 0;
if(strcasecmp(color_string1,"brown") == 0)color_code = 1;
else if(strcasecmp(color_string2,"black") == 0)color_code = 2;
else if(strcasecmp(color_string3,"yellow") == 0)color_code = 3;
  scanf("%d",&color_code);
  printf("value is: %d\n",color_code);
  return 0;
  } 
  • 1

C

107,302 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator