Thread: Resistor value to color code and vice versa

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Eddie Ramos's Avatar
    Join Date
    Jan 2012
    Location
    CA
    Posts
    6

    Resistor value to color code and vice versa

    I'd like to thank you all for your time and help in advanced much appreciated.

    Microsoft Visual Studio 2012
    C++ Console Application

    What my program is to do:
    -ask user for value ex. 200 ohms
    - output the value in color ex brown black brown
    and vice versa
    -ask user for color ex brown black brown
    -output the value ex 200 ohms

    a few background summary:
    I'm very new to C++(2 days) i have self taught myself c++ enough to make my very first working program. i got it to output the value based on the color numbers entered. basically am trying to make a resistor color code calculator.

    My problem:
    - it only outputs the value based on color numbers
    how do i make it output value in colors?
    - is there better ways of doing this?

    Code:
    #include <iostream>
    #include <cmath>
    using namespace std;
    
    
    int main() {
        double colornum,multiplier;
    
    
        cout<<"0 = black"<<endl;
        cout<<"1 = brown"<<endl;
        cout<<"2 = red"<<endl;
        cout<<"3 = orange"<<endl;
        cout<<"4 = yellow"<<endl;
        cout<<"5 = green"<<endl;
        cout<<"6 = blue"<<endl;
        cout<<"7 = violet"<<endl;
        cout<<"8 = grey"<<endl;
        cout<<"9 = white" <<endl<<endl;
    
    
        cout<<"Enter 1st & 2nd band color numbers: ";
        cin>>colornum;
        cout<<"Enter 3rd band color number(Multiplier): ";
        cin>>multiplier;
    
    
        cout <<"The color code of a "<<colornum<<multiplier<< " resistor is: ";
    
    
        if ( multiplier == 0) {
            multiplier = colornum * pow( 10,0 );
        } else if ( multiplier == 1 ) {
            multiplier = colornum * pow( 10,1 );
        } else if ( multiplier == 2 ) {
            multiplier = colornum * pow( 10,2 );
        } else if ( multiplier == 3 ) {
            multiplier = colornum * pow( 10,3 );
        } else if ( multiplier == 4 ) {
            multiplier = colornum * pow( 10,4 );
        } else if ( multiplier == 5 ) {
            multiplier = colornum * pow( 10,5 );
        } else if ( multiplier == 6 ) {
            multiplier = colornum * pow( 10,6 );
        } else if ( multiplier == 7 ) {
            multiplier = colornum * pow( 10,7 );
        } else if ( multiplier == 8 ) {
            multiplier = colornum * pow( 10,8 );
        } else {
            multiplier = colornum * pow( 10,9 );
        }
        cout <<multiplier<<endl;
        return 0;
    }
    Last edited by Eddie Ramos; 09-29-2012 at 04:01 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Chaning AM to PM and vice versa
    By EssiJoon in forum C Programming
    Replies: 2
    Last Post: 04-19-2012, 09:36 PM
  2. Resistor Color Decoder for a 6 band resistor
    By nivoca in forum C Programming
    Replies: 2
    Last Post: 06-25-2011, 12:44 PM
  3. int to char and vice versa
    By mekaj in forum C++ Programming
    Replies: 13
    Last Post: 12-12-2005, 11:35 AM
  4. Problem: far to near copy, and vice versa
    By aaronc in forum C Programming
    Replies: 1
    Last Post: 06-16-2004, 06:37 AM
  5. Binary to ascii and vice versa
    By thenrkst in forum C++ Programming
    Replies: 13
    Last Post: 03-30-2003, 01:17 AM