check

hi every one

"I want to help me to know where is the error in my programming"

Q:
Write a C++ program that reads several marks. For each of these marks, your program should determine and display the correspondent grade. The number of marks entered is not known. Use a sentinel value to stop. The grade will be determined by the following formula:
If the mark is greater than or equal 90, the grade is A. If the mark is greater than or equal 80 and less than 90, the grade is B. If the mark is greater than or equal 70 and less than 80, the grade is C. If the mark is greater than or equal 60 and less than 70, the grade is D. If the mark is less than 60, the grade is F


try answer:

#include <iostream>
using namespace std;
int main ()
{
int mark;
char grade;

cout << "Enter a mark:";
cin >> mark;
cout <<endl;

while (mark != -1)
{
if(mark >= 90)
grade ='A';
else if (mark >= 80)
grade ='B';
else if(mark >= 70)
grade ='C';
else if(mark >= 60)
grade ='D';
else
grade ='F';

cout<<"The grade of this mark"<<mark<<" is"<< grade<<endl;


return 0;
}

in the Microsoft Visual Studio 2010

explain :
1>------ Build started: Project: lab4, Configuration: Debug Win32 ------
1>Build started 11/28/2013 2:44:36 PM.
1>InitializeBuildStatus:
1> Touching "Debug\lab4.unsuccessfulbuild".
1>ClCompile:
1> q1.cpp
1>d:\users\staff\documents\visual studio 2010\projects\lab4\lab4\q1.cpp(32): fatal error C1075: end of file found before the left brace '{' at 'd:\users\staff\documents\visual studio 2010\projects\lab4\lab4\q1.cpp(4)' was matched
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.39
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You don't have a closing brace for your while (...) loop.
well, first of all, there is no need of the while loop, so remove it at once.
next, your program assigns, grade B to marks>=80 which includes marks>=90 also
similar mistakes for grade C & D too...

so your else if condition should be : (marks<90&&marks>=80) //for grade B of course...

this should do the job...
one more thing, your question asks for several marks to be enterd and graded...

so you should use an array instead of a single variable.
I just want to apologise publicly to ajh32 for reporting your post above. I meant to report the post from Virginiajem that you were replying to, as that user is clearly a spambot, but I accidentally clicked on the wrong Report button. Sorry :(


now remove ( while loop )

thanks for all
Topic archived. No new replies allowed.