Hello aftselakhis,
Your program is on the right track and has many usable parts, but dors have some problems.
Line 2. It is best not to use this.
Line 8. Since this is for an average I made it a "double" so the final answer is more correct. Integer division tends to round the number not will because it will drop the decimal portion of the calculation. And when you get to the part
ave37/=ctr;
you should check that "ctr" is not zero before you do your division and the program crashes.
Something like:
Comes to mind right off.
Line 9. Because "prodd" can become a very large number you need to learn what different data types can hold and what their limits are. Have a look at this
https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx Right now you are a long long way from using the right data type.
Here is an example:
Enter a number: 2
Enter a larger number: 45
A. Total of values divisible by 6 & 4: 72
B. Average of values divisibe by 7 & 3: 31.5
C. Product of all odd values: 9481495526376579231
Press Enter to continue
|
Notice the value of line C.
Line 19. You can use "+=" here as you used "/=" and "*=".
Line 24. saeidsj is correct. Each iteration through the for loop and then each time you enter the if statement you are defining and setting "ctr" to zero then adding one, so the most it can be is one. It works better to move this definition at the top with the rest of your variables.
Lines 28 - 31. If neither if statement is true the else part will break out of the for loop to early. You do not need this else part.
Line 33. Has been covered.
Lines 35 - 38. To deal with only the odd numbers after line 37 add the line
i==;
. Now every time the if statement is entered you will only be using the odd numbers.
Lastly watch your indenting. Line 21 should line up with line 17. And line 43 should be indented.
Hope that helps,
Andy
Edit: