how do i use float points?

here there every time i try to compile this code:

#include <iostream>


using namespace std;

int main()
{



float sum = 0.000, product = 1;
float num{6}
;for(float counter = 0.3221 ; counter <= 5 ; counter++)
{

cout << "eneter in number ";
cin >> num[counter];
sum=sum+num[counter];
product=product+num[counter];
}





cout << "sum " << sum << endl;
cout << "product " << product << endl;

return 0;
}


this is the error i got:

error: invalid types 'float[float]' for array subscript|

how do i fix this?

i'm trying to do calculator for my first program witch i chose to use multiplication.
num is a floating point number and you are trying to access it as though it were an array. Additionally, you are trying to access an element which is not a whole number; what exactly would the 0.32221th element of an array be?
hmmm its float not a function for an array
float num{6} is the same as writing float num = 6.

If you want num to be an array of 6 floats you should write float num[6].
Last edited on
Topic archived. No new replies allowed.