converting bits to bytes to kilobytes with mod

I was recently enrolled in CS115 at university.
We work on problem solving with c++.
I have code that I have work on for many hours.
It display how many kilobytes and bytes and the remainder of bits are in the inputted amount of bits.
I believe I am very close but it not working for me.


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

int main ()
{
    int bits;
    cout << "Enter a number of bits";
    cin >> bits;
    const int bits_in_byte = 8;
    const int bytes_in_kilobyte = 1024;
    int bytes = bits / bits_in_byte;
    int leftover_bits = bits % bits_in_byte;
    int leftover_bytes = bytes % bytes_in_kilobyte;
    int kilobytes = bytes / bytes_in_kilobyte;
    cout << "There are " << kilobytes << "kilobytes and " << leftover_bytes << " bytes and " << leftover_bits << " bits in " << bits << " bits " << endl;
    system("pause"); 
    return 0;
}


What do you think? It seem to give me wrong output leftover_bytes.

Excuse my wrong English.

Thank you.
Looks fine to me.
Why do you think it's wrong, that is, what is your input and what is the expected and actual output?
I am very sorry to waste your time thank you very much.
Topic archived. No new replies allowed.