Modulo (%)

Hello,

First a little background might make this more clear/interesting. I am an electrician, industry standard says that in an electrical panel breakers are numbered as such:

breaker 1 :: breaker 2
breaker 3 :: breaker 4
breaker 5 :: breaker 6
........ :: .........
so on and so forth.

further more industry standard says that the wires that land on breaker 1 and 2, would be black, 3 and 4 would be red, and 5 and 6 would be blue. Following that pattern, breaker 7 and 8 would be black and the pattern is repeated. There is an old trick to quickly figure out what color wire would land on, say breaker 19. Take 19 / 6 = 3 with a remainder of 1. The remainder of 1 would make it a black wire because you mentally associate the remainder with a breaker.

Another quick example in case that isn't clear. "hmmm what color wire goes on breaker 59?" 59 / 6 = 9 with a remainder of 5. "BLUE!" Because the remainder of 5 is the same color as the #5 breaker.

When I read what % does while reading the c++ tutorial I immediately wanted to make a program that would:

ask user for a breaker number, then tell you what color of wire goes under said breaker.

I have started writing this up but, I have gotten stuck with how to make modulo work!

here is what I have so far (just working on the black wire for odd breakers so far):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;

string color;
int black;
int breaker_number;

int main ()
{

cout << "What breaker do you want the color of?\n";
cin >> breaker_number;

if (breaker_number % 6 = 1)
{
     color = black;
}

cout << breaker_number << " is the color: " << color << "." << '\n';

}


So if the input number divided by 6 has a remainder of 1, cout should say "7 is the color: black." but it doesn't. WHY!?!

After typing all of this I think it is because of the way math is done. 7 / 6 = 1.66, or since I'm not using double, 1? I want it to read: 7/6 = 1 remainder 1. Do I need to #include something else? Maybe I am just not this far in my readings.

Anyways thank you if you have stayed with me through this whole wall of text, and thank you all the more if you know how to help me!
Because it does not compile.
If you read the compiler error messages, you may figure out how to fix it.
If you don't understand said messges, the least you can do is post them.
if (breaker_number % 6 = 1)

change = to ==

color = black;
what is the value of the variable named black?
Last edited on
Later you'll realize that the identifier and the content of a variable does not relate.
color = "black";
changed = to == worked great lol, can't tell ya how much time put into this.
Topic archived. No new replies allowed.