Program compiles, but won't give correct output

I'm taking my first C++ class at school. and our first project is to write a program that can convert a whole number between 1 and 8 to binary. I wrote a code that I feel should work and it does compile, however when I run it, it will only give me "0000" for the answer. Can somebody please help!

[code]
Put the code you need help with here.
#include <iostream>
using namespace std;

int main()
{
int whole_number, Remainder1, Remainder2, Remainder3, Remainder4, First, Second, Third, Fourth;

cout << "Enter a whole number between 1 and 8: ";
cin >> whole_number;

First = whole_number / 8;
Remainder1 = whole_number % 8;
Second = Remainder1 / 4;
Remainder2 = Second % 4;
Third = Remainder2 / 2;
Remainder3 = Third % 2;
Fourth = Remainder3 / 1;


cout << "The binary equivalent is " << First << Second << Third << Fourth << endl;

return 0;

}
First, code tags in your post are broken.

I took your program and added more output statements:
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
#include <iostream>

int main()
{
    using std::cout;
    int whole_number, Remainder1, Remainder2, Remainder3, Remainder4, First, Second, Third, Fourth;

    cout << "Enter a whole number between 1 and 8: ";
    std::cin >> whole_number;

    First      = whole_number / 8;
    Remainder1 = whole_number % 8;
    cout << First << ' ' << Remainder1 << '\n';

    Second     = Remainder1 / 4;
    Remainder2 = Second % 4;
    cout << Second << ' ' << Remainder2 << '\n';

    Third      = Remainder2 / 2;
    Remainder3 = Third % 2;
    cout << Third << ' ' << Remainder3 << '\n';

    Fourth = Remainder3 / 1;
    cout << Fourth << '\n';

    cout << "The binary equivalent is " << First << Second << Third << Fourth << std::endl;
    return 0;
}

Lines 16 and 20 ...
keskiverto,

thanks for the reply. However when i put your program in DEV C++ and ran it, it still gave me all zeros for the final cout statement. Did it work for you?
I just added a bunch of cout's, and the modulus is not working correctly. when i input 7, it is correct when divided by 8. but then when it does 7 divided by 4, it says it is 1 with a remainder of 1, and then everything after that is giving zeros.. ive been trying to figure this out for hours and am extremely lost as to why this wont work
With input 7 the Remainder1 is 7. That is good.
The Second is 1 and that is good too.

Second % 4 == 1 % 4 == 1. Is that really the Remainder2 that you are looking for?
no sir, the remainder should be 3, correct?
Correct. You clearly should not compute remainder from the Second, should you?
Topic archived. No new replies allowed.