+ 1

Who can help with fixing the code?

O randomly gives out strange numbers and I can't understand why this happens(I started learning C++ just 2 weeks ago, so I don't really understand it). ------------------------------------------------------------------ #include <iostream> using namespace std; int main() { int ages[5]; int bilet = 50; int mAge; double sell1; double a = 0.5; double itog; cin >> mAge; for (int i = 0; i < 5; ++i) { cin >> ages[i]; if(mAge > ages[i]){ mAge = ages[i]; } } sell1 = a * mAge; itog = bilet - sell1; cout << itog << endl; }

17th Feb 2021, 12:05 PM
pollok670
pollok670 - avatar
7 Antworten
0
I don't see anything wrong with the code. Could you provide some valid input and output values ?
17th Feb 2021, 1:33 PM
Hima
Hima - avatar
0
What are you finding by this code? If you are finding maxAge by loop among 5 input values, then it should be if(mage<age[i] ) Otherwise it finds a random mage which is less than initial one... hope it helps...
17th Feb 2021, 1:43 PM
Jayakrishna 🇮🇳
0
@Hima, in general, this code should take 5 numbers(years) and output the smallest of them. After this number is converted to a discount and subtracted from the variable bilet and output a number with a discount. But it works like that by accident and eventually displays either the normal number, it's just a nonsense.
17th Feb 2021, 3:19 PM
pollok670
pollok670 - avatar
0
pollok670 give me an input and an expected output.
17th Feb 2021, 4:49 PM
Hima
Hima - avatar
0
Hima, let's say the input is 11 42 24 53 35, and the output should then be 44.5. But it works 50-50 and outputs either the desired number, or some nonsense like 9.98322 e + 08 or 1.77942 e+08 and something like that.
17th Feb 2021, 5:09 PM
pollok670
pollok670 - avatar
17th Feb 2021, 5:56 PM
Hima
Hima - avatar
0
Thanks, Bro.
18th Feb 2021, 12:03 AM
pollok670
pollok670 - avatar