Im learning C++ at the minute with book by Stanley Lippman. Im studying paragraph that named "class Bitset". There is an exercise where he gives me numerical sequence to transfrom into bitset<32>.
The numerical sequence is: 1,2,3,5,8,13,21. Can i ask you is my code right for peresenting this numerical sequence? Lippman also want me to use each bit in bitset to represent sequence, but is bitset can store more than 1 value in it? Im doing it first time and the only idea i got is:
int index = 0;
const int size_ = 7;
unsigned long f2[size_];
int main()
{
setlocale(LC_ALL,"rus");
string try1;
cout << "Type your numerical sequence in binary code: " << endl;
while (cin >> try1) {
bitset<32> go(try1);
if ( go.to_ulong() > 21 ) { cout << "End of sequence" << endl; break; }
f2[index] = go.to_ulong();
index++;
try1.clear();
go.reset();
}
for ( index; index >= 0; index-- ) {
cout << f2[index] << " ";
}
system("pause");
return 0;
}