#Simple Question
38 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
@buoyant hornet
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
!f
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main() {
float n, k, mark, a;
a = 0;
k = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> mark;
a += mark;
}
cout << fixed;
cout << setprecision(1);
k = a / n;
if (mark == 3) {
cout << "None" << endl;
}
if (a == 5 * n && mark == 5) {
cout << "Named" << endl;
} else if (k >= 4.5 && mark > 3) {
cout << "High" << endl;
} else if (mark > 3 && k < 4.5) {
cout << "Common" << endl;
}
return 0;
}
were u having issues ?
Yeah, I was trying to solved this problem but when I submitted it, I got "Wrong Ans", I've try my code and I got the same output
Um, I was new to discord so I don't really understand the features. Can you see my question photos?
what is fixed?
why are you setprecision(i) you need to help us so that we can help lol
Isn't it is used for setprecision?
that its correct setprecision(1) will set precision to 1 decimal
Sorry, setprecision (1) so I can keep 1 number behind comma, because the average that we want to compare are 4.5. If I try to find average without setprecision (1), if I got like 4.6 it will turn to 4 and made the average was less than 4.5 when it was supposed to be greater than 4.5
Sorry for my bad English too..
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n =0;
float result =0, mark =0, sum =0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> mark;
sum += mark;
}
result = sum / n;
cout << fixed << setprecision(1);
//fix the if's
if (result == 3) {
cout << "None" << endl;
}
else if (result == 5 ) {
cout << "Named" << endl;
} else if (result >= 4.5 ) {
cout << "High" << endl;
} else if (result > 3 ) {
cout << "Common" << endl;
}
return 0;
}```
I still got wrong ans with this code
see comment ``fix the if's`
Do you mean I should changed the if?
!f
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n = 0;
float result = 0, mark = 0, sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> mark;
sum += mark;
}
result = sum / n;
cout << fixed << setprecision(1);
if (result == 3) {
cout << "None" << endl;
} else if (result == 5) {
cout << "Named" << endl;
} else if (result >= 4.5 && mark > 3) {
cout << "High" << endl;
} else if (result > 3 && result < 4.5) {
cout << "Common" << endl;
}
return 0;
}
also a small note I reccomend against using #include <bits/stdc++.h>
it's non standard and should honestly never be used
see i was confused because of random fixed which comes from std::fixed)
Ok! Thanks for telling me
Okay, thanks
In general don't use non-standard headers unless they're from an external library that's known and maintained
any file that ends in a .h is not part of std c++ libs
(Except those internal includes but no one uses them, they're only used by stdlib)
using namespace std is probably fine in this scale
but afaik doing that include loads the entire stdlib into the compiler
Not that I'd ever do it but yk
And before anyone points out that C headers are a part of stdlib
while you're right
even the compiler tells you to use the C++ variant instead
cmath instead of math.h for example
@buoyant hornet Has your question been resolved? If so, run !solved :)
!solved