0
I can't figure out what's wrong with my codeš
#include <iostream> using namespace std; int main() { int mark1,mark2,mark3; int totalmarks,obtainedmarks,averagemarks; totalmarks = 300; cout <<"please enter mark1:"; cin >>mark1; cout << "please enter mark2:"; cin >>mark2; cout<< "please enter mark3:"; cin >>mark3; obtainedmarks = mark1 + mark2 + mark3; averagemarks = obtainedmarks / 3; cout << "totalmarks are: ",totalmarks << endl; cout << "obtainedmarks are:",obtainedmarks << endl; cout << "averagemarks are:",averagemarks << endl; if averagemarks > 50 { cout << the student has passed; } else { cout << the student has failed; } } https://code.sololearn.com/W6uo7y639MIB/?ref=app
2 Answers
+ 2
It could be better if you revised lesson. Crying will never solve a problem.
I'm listing some problems so you can try to fix them. btw compiler also tells about them nicely.
1. You need to chain << operators. using comma to separate values will not work.
cout<<"totwlmarks are: "
<<totalmarks<<endl;
same for other cout statements.
2.Use parantheses () around condition. It's explained in C++ course.
3. int divided by int always results in int (not double or float) so average marks will always be integer if you need more accuaracy use float or double data type.
+ 1
Thanks a lot š®š³Omkarš