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>
usingnamespace std;
int main ()
{
int bits;
cout << "Enter a number of bits";
cin >> bits;
constint bits_in_byte = 8;
constint 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.