Struggling with pointers and DMA | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Struggling with pointers and DMA

Hey (again), I’m trying to complete the 36 end of module project for c++, and could someone please explain to me how to insert pointers and why my code doesn’t work? #include <iostream> using namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } int min = ages[0]; for(int i = 0; i < 5; i++) { if(ages[i] < min) min = ages[i]; } float percentage = min; float discount = 50/100 * percentage; float sum = 50 - discount; cout << sum; return 0; }

1st Mar 2021, 5:20 PM
Millü
Millü - avatar
2 Answers
+ 2
Dividing an integer by another integer in C++ will yield an integer as well, i.e. the decimal part is truncated. Therefore: 50 / 100 = 0 If you expect a decimal result, at least one operand has to be a floating point type, e.g. 50.0 / 100 = 0.5 50 / 100.0 = 0.5 50.0 / 100.0 = 0.5 Everything else should be fine. Why are you worrying about inserting pointers?
1st Mar 2021, 5:26 PM
Shadow
Shadow - avatar
0
cheers! i had been stuck on this for quite a while and i assumed that i needed to use pointers and DMA to solve it as it was the last few topics before the project
1st Mar 2021, 5:41 PM
Millü
Millü - avatar