float array error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

float array error

#include<iostream> using namespace std; int main() { float i,n, sum=0.0; cout<<"calculating of total expenditure list"<<endl; cout<<"enter the number of total things you bought: "<<endl; cin>>n; float money[n]; for(i=1;i<=n;i++) { cout<<i<<" no product cost :"<<endl; cin>>money[i]; sum += money[i]; } cout<<"total money used: "<< sum<<" taka"<<endl; return 0; } it doesn't run using float, but runs using int.

28th May 2020, 2:38 PM
Rubayet Alam
Rubayet Alam - avatar
10 Answers
+ 1
You can too use the youtube video for you error.just mention the line in which the problem is. We all are going to help you. Sololearn community team🤟
28th May 2020, 2:46 PM
Piyush
Piyush - avatar
+ 1
There is no float value. Where do you want to work with float values, with which and from where are they coming from?
28th May 2020, 4:02 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
You are mixing too many things within your code. i is declared as float too, but actually assigned with integer values and used as integer. Nothing can work with that code! Just read the compiler messages...
28th May 2020, 5:52 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
View this as simple code taking a float 3 times into an array and sum it up. No error handling. https://code.sololearn.com/c13n5dJi0fuP/?ref=app
28th May 2020, 5:54 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
An array is a kind of a list and I did not use a type "List" here, it is just the variable name of the array...
28th May 2020, 6:09 PM
Sandra Meyer
Sandra Meyer - avatar
0
In this program i can't use float anywhere. It only runs through int data type.
28th May 2020, 2:51 PM
Rubayet Alam
Rubayet Alam - avatar
0
How can I use float array ?
28th May 2020, 5:16 PM
Rubayet Alam
Rubayet Alam - avatar
0
You have no float numbers to store! This is what you have to fix first.
28th May 2020, 5:19 PM
Sandra Meyer
Sandra Meyer - avatar
0
I am taking user input. Can i take 1.5 in int array?
28th May 2020, 5:23 PM
Rubayet Alam
Rubayet Alam - avatar
0
Thank you. But you have used list here. Is it possible to do without list?
28th May 2020, 6:06 PM
Rubayet Alam
Rubayet Alam - avatar