0
Kindly debug the following code
#include <iostream> using namespace std; int main() { int total,grade counter,grade,average; total=0; grade counter=1; while(grade counter<=3) { cout<<"enter grade"; cin>>grade; grade counter=grade counter+1; } average=total/3; cout<<average; return 0; }
9 Respostas
+ 5
Can't have spaces in variable names.
+ 5
And you ask for input, but don't use it.
+ 4
You have to initialize all your values:
    int grade_counter=1;
    int grade = 0;
    int average = 0;
    int total = 0;
+ 4
It is printed every time the loop runs. You don't use line ends so it looks odd.
+ 3
Hint: average = 0/3
+ 1
thanks alot sir paul jacob and 
mr. jay for ur time and kind guidance...
God Bless u...
0
//can you plz compile the code and verify it..
//i still not getting acurate result...
#include <iostream>
using namespace std;
int main()
{
    int grade_counter=1;
    int grade;
    int average;
    int total ;
    while(grade_counter <=3)
    {
    cout<<"enter grade";
    cin>>grade;
    total=total+grade;
    grade_counter=grade_counter+1;
    }
    average=total/3;
    cout<<average;
    return 0;
}
0
great it make sense...
getting accurate results..
but why it shows 
enter gradeenter gradeenter gradeenter as a o/p after compiling
rather than it should show "average"
0
//its my final code that is working as i wish
#include <iostream>
using namespace std;
int main()
{
    int grade_counter=1;
    int grade=0;
    int average=0;
    int total=0 ;
    while(grade_counter <=3)
    {
    cin>>grade;
    total=total+grade;
    grade_counter=grade_counter+1;
    }
    average=total/3;
    cout<<"average="<<average;
    return 0;
}






