+ 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; }
7 odpowiedzi
0
I don't see anything wrong with the code. Could you provide some valid input and output values ?
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...
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.
0
pollok670 give me an input and an expected output.
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.
0
pollok670
https://code.sololearn.com/cX8l5yr9YC26/?ref=app
Here's the working code
0
Thanks, Bro.