0
Arrays challange in c++
Can somone tell me why my code outputs the right values followed up by very large numbers?The challange is to output the array items discounted by the given input. #include <iostream> using namespace std; int main() { double items[]= {500, 12.4, 94, 45, 3, 81, 1000.9, 85, 90, 1, 35}; double dis; cin>>dis; double value; for(int i=0;i<sizeof(items);i++) { value=items[i]-(items[i]*(dis/100)); cout<<value<<" "; } return 0; }
3 odpowiedzi
+ 5
sizeof (items) is outputting 88 ,total size occupied by each double in memory 8 bytes *11=88 bytes
If you are looking to get number of items it should be
sizeof(items)/ sizeof (items[0])
+ 1
Thank you:)
0
Wouldn't it be better to replace sizeof(items) with items.length()