Hi ! I just started learning C++ without any prior knowledge. So, this assignment wants me to code for dropping the lowest score in N number of homework and finding the average grade. My course does not cover about array, but for loop only. My problem is that if there are 5 homework scores inputted, the lowest score is always outputted '0.' Please let me know how to pick the right lowest score as coding it! Thank you.
It seems you're on the right track, but a lot of this stuff could be simplified within one loop.
I think what's happening is that when you put in a number less than 5, you still have the other if statements that deal with hw6 and hw7 so the code freaks out - but I'm not totally sure if that's the reason. Also, I noticed that when I ran your code, if hw1 was less than hw2, then no matter if any other homework was smaller than hw1, it would always output hw1 as the lowest homework.
The code below is more general (in terms of if it's traditional homework assignments where it is graded from 0 to 100) and I think it's what you're looking for. Let me know if you have any questions! :)
I think you meant that the course you are taking has not yet covered arrays. If it didn't cover arrays at all, I would strongly advise you to gtfo of that course.
The solution is simpler that it looks, you don't need to make it so complicated:
1 2 3 4 5 6 7 8 9 10 11 12
double lowest_hw = 99999999;
double hwN = 0.0;
std::cout << "Enter homework grade (Enter -1 to quit)";
while(std::cin >> hwN)
{
if (hwN == -1.0) break;
if (hwN < lowest_hw) lowest_hw = hwN;
std::cout << "Enter homework grade (Enter -1 to quit)";
}
std::cout << "The lowest score is: " << lowest_hw << std::endl;
> else if(i == 5) cin >> hw6;
> else if(i == 6) cin >> hw7;
As KittyIchigo1 says, these don't happen when n is 5
> double hw1, hw2, hw3, hw4, hw5, hw6, hw7;
> double lowest_hw;
None of these have any initial value.
It looks like today, for you, in this particular program, hw6 and/or hw7 just happen to be zero.