Advice on how to get started on this project?!?!

I'm going to write a program that will prompt the user for the colors on a 4 band resistor and then calculate and cout the resistance and tolerance of that resistor. I need to eventually write this to read a 4 5 6 band resistors. However, I'm just going to attempt the 4 band for now. I really could use some advice on how to get started on this.

I've tried writing as much information down that I could on what I need to use in my code and have roughly started a flowchart but still have no idea how to begin implementing this into code. I'm a beginner and could really use some advice.

It would be nice to see the code first and understand it then build it my own way from the understanding of what I gathered. However, I cannot find an example. Therefore, does anyone have some advice on how I can get started? How many mains will I need? How many headers will I use? How many functions do I build? I know there are several ways to answer this. I'm just asking for alittle help to get me started this weekend. Thanks.

well, before you do ANY coding, make sure you have a "gameplan". Design a flowchart on paper and write a tech doc specifying how the program runs. Be INCREDIBLY anal about this, if you miss something your project can and will go sideways very quickly on you. After that, start simple. Build the main function (just to kick-start the project) then build your documented functions one at a time. And if you really want this sucker to be tougher than nails, do it in a test-driven environment. Where each new function is allowed to stay in your program after passing a "Trail by Fire" test. But we can explain that to you later if you want. You really just need to know how each and every aspect of your program needs to run and then don't compromise.

(hypothetical)
i.e. My function sorts this array of elements that are of unknown size, I need to do this as fast as I think possible and I can't use STL algorithms. If My function encounters an error, report it and try to continue. If it can't continue, return -1.

Then I would write that function to reflect EVERYTHING in the documentation. Always document BEFORE you write code. It would be a template function (the unknown size part). the whole function would be at min some sort of quick-sort algorithm (fast as possible) and it would have a return type of int and have printf() tracing through-out the function in case something goes wrong (errors).
Last edited on
From my experiences so far on this forum, I've noticed that engineers seem to have the hardest part starting with programming, not just C++, but all languages. It must be something to do with the fact that numbers is all they really use (please don't take that as an insult). But nonetheless, we all need help sooner or later.

I don't typically do this, but I decided to sit down and take a pretty quick swing at your problem. This is poorly implemented and even more so commented. I hope you can follow along:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>

void EnterBands(int numOfBands, int bands[]);
void DisplayResistance(int numOfBands, int bands[]);

int main() {
   int numOfBands;
   int bands[6];
   std::cout << "Please enter the number of bands on the resistor (4 - 6):";
   // There is no error testing done with choice, but should be implemented
   std::cin >> numOfBands;

   switch (numOfBands) {
      case 4: ///< 4 Band Resistor
         EnterBands(numOfBands, bands);
         break;

      case 5: ///< 5 Band Resistor
         break;

      case 6: ///< 6 Band Resistor
         break;
   }

   DisplayResistance(numOfBands, bands);
   return 0;
}

void EnterBands(int numOfBands, int bands[]) {
   for (int i = 0; i < numOfBands; i ++) {
      std::cout << "\nPlease enter your band #" << i + 1 << ":";
      // Can convert from colors later on
      std::cin >> bands[i];
   }
}

// This function is used to convert the bands into resistances
void DisplayResistance(int numOfBands, int bands[]) {
   long resistance = 0;

   // Calculates the bands up to the multiplier
   for (int i = 0; i < numOfBands - 2; i ++) {
      resistance *= 10;
      resistance += bands[i];
   }

   // Calcualtes the multiplier
   for (int i = 0; i < bands[numOfBands - 2]; i ++)
      resistance *= 10;

   std::cout << "Your resistor is rated at:\n";
   std::cout << "\tMin:" << resistance -
             (resistance * bands[numOfBands - 1] / 100) << "\n";
   std::cout << "\tMax:" << resistance +
             (resistance * bands[numOfBands - 1] / 100) << "\n";
}


Now, I want you to know, I learned about resistors about 10 years ago, and since, I have completely forgotten how they're marked, I just knew it involved colors. After a search or two on wikipedia, I stumbled across a way to calculate the values, and a really brief example.

Wikipedia wrote:
For example, a resistor with bands of yellow, violet, red, and gold will have first digit 4 (yellow in table below), second digit 7 (violet), followed by 2 (red) zeros: 4,700 ohms. Gold signifies that the tolerance is ±5%, so the real resistance could lie anywhere between 4,465 and 4,935 ohms.


Here is the above output:
Please enter the number of bands on the resistor (4 - 6):4

Please enter your band #1:4

Please enter your band #2:7

Please enter your band #3:2

Please enter your band #4:5
Your resistor is rated at:
        Min:4465
        Max:4935


I hope this gets you a few steps closer.

Note: I didn't implement the color's mainly because that would have taken a while, but you can at least see the basic outline of the program. All bands, minus the tolerance, are going to be a set value, so you can have that in one function, get the value of the tolerance in another function, or the same if you're brave, and you'll end up just reusing the code for Display Resistance.
Topic archived. No new replies allowed.