Resistor Color Code Calculator


I need with this assignment:

Write a C program that asks the user to enter a resistor value (in Ohms). The program will then determine the color bands for the resistor and display the data to the user. Only display data for the three bands (1st band, 2nd band, and multiplier).

Use an enumeration for the colors.



Specifications:
Only one function may called from within main() for program execution.
Describe the program to the user.
Prompt the user for input.
Assign input from the user appropriately.
Display the results to the user.
Be sure to handle cases where the user enters an invalid selection.

Requirements:
Modular design is required. Use of functions written in C is a must.
Use cout and cin.
Use of comments within this program is required.
Only one function may be called from main().
Use of an enumeration is required.
Use of a switch statement is highly recommended.



Current Code:

#include <iostream>
#include <conio.h>
#include <cmath>

using namespace std;


//Function Prototypes
void Program(void);

enum colors {black, brown, red, orange, yellow, green, blue, violet, gray,
white, gold, silver};




//main ()
int main(void)
{
Program();
system("pause");
}

//start of the program



void Program()
{

enum colors color;
char colorcode[25];
char colorArray[30];
int null = 0;
int value;



char *colorName[] = {"black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "gray", "white", "gold", "silver"};

cout << " Please enter a reistor value in Ohms.\n\n";
cin >> colorcode;

strcpy(colorArray, colorcode);


cout << colorArray;





for (int i=0; i < sizeof(colorcode); i++)
{
if(colorArray[i] == '\0')
{
null = i;
break;
}
}

switch (value)
{
case 4:
case black:
{
cout << "Black";
}
break;

}

}
Last edited on
[code] "Please use code tags" [/code]
Modular design is required. Use of functions written in C is a must.
Only one function may be called from main().
¿? That doesn't make sense.

¿What is giving you trouble?
I am trying to assign the individual resistor values of the array to the colors in the enum

so if I was to enter a resistor value of 4600 ohms. I would want to print out the color code of resistor.

example:

if user enter resistor value: 4600

program prints:

4 = yellow
6 = green
00 = red
Topic archived. No new replies allowed.