Hello everyone.
I'm stuck with an error message that neither I nor any of my computer science peeps can understand. The program I wrote is meant to be a simple decimal to binary converter, but with this message it's more complicated than I thought.
Here's the code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int num = 0;
int k = 0;
int max = 0;
bool binary[100];
cout << "Enter a decimal number: " ;
cin >> num;
while (pow(2,k) <= num)
k++;
k--; // Decrements the power after the highest power of 2 is found.
max = k;
while (k >= 0 && num > 0)
{
if (pow(2,k) > num)
binary[k] = 0;
else
{
binary[k] = 1;
num -= pow(2,k);
}
k--;
}
while (max >= 0)
{
cout << binary[max];
max++;
}
return 0;
}
The error exactly says:
...\dectobin.cpp:27: error: invalid types 'bool [100][double]' for array subscript
...\dectobin.cpp:30: error: invalid types 'bool [100][double]' for array subscript
If it helps, I'm using Quincy... but only because my lecturer is using Quincy.
Any help is appreciated greatly.
PS, is there any reason why the variable k can't be of type int?