So i have a task : enter N , and a "social score".
After which you write N amount of marks, for an F you get "-5" score , for a D "-3",
for a C "-1" , and for a B you get 0, or your score remains the same. After you've written N amounts of marks , you need to print your remaining score , or if you have already dropped to 0 , print ," you have lost all your points."
#include <iostream>
using namespace std;
int main()
{
int N, Score;
char Mark;
cin >> n >> Score;
if ((n < 1 || n > 10) || (Score < 10 || Score > 50)) {
return -1;
}
for (int i = 0; i < N; ++i) {
if (Score > 0) {
cin >> Mark;
}
}
switch (Mark) {
case 'F': Score -= 5;
case 'D': Score-= 3;
case 'C': Score -= 1;
case 'B': Score -= 0;
}
if (Score > 0) {
cout << Score;
}
else {
cout << "you have lost all your points.";
}
return 0;
}
I really don't understand where I'm going wrong with this , but im pretty new at C++ , so any help will be highly appreciated
After the statement(s) for a case, you need break; - otherwise the case 'drops' through to the following code. So for case 'F', 5 is subtracted from Score, then 3 subtracted, then 1 subtracted. So you end up with 9 subtracted from Score for F!