Urgent help required for a grading system

hey guys, im new to C++ and im doin an assignment. In my problem, you gotta search for a student's name and then make the program display the name, corresponding marks and the grading. I've got everything else right, but the grading just doesnt work. I get an error called x is not initialized. Can anyone help me with the prob? I need to hand this over asap.

void displaynames(){
string seek;
int i,x;

cout<< "Enter a student's name"<<endl;
cin >> seek;
for (i=0;i<10;i++){
if (nameArray[i]==seek){

markArray[i]=x;
if (x>75 && x<100){
cout << nameArray[i]<<markArray[i]<< "D" <<endl;
}
if (x>74 && x<65){
cout << nameArray[i]<<markArray[i]<< "M" <<endl;
}
if (x>40 && x<64){
cout<< nameArray[i]<<markArray[i]<< "P" <<endl;
}
else
cout<< nameArray[i]<<markArray[i]<< "F" <<endl;
}
}
}
It looks like maybe you have your assignment backwards:
markArray[i]=x;
Maybe it should be:
x=markArray[i];
Or better yet just use makArray[i] in your if/else chain.

x is not initialized is indeed what you have here.
This line assigns whatever random value x happens to have, to markArray[i]
 
    markArray[i]=x;

and so on.
Try changing that to
 
    x = markArray[i];
@jlb and @Chervil , thnks so much guys!!! I tried it n it works! how stupid of me, i've indeed had my assignment backwards!
thank you guys sooo much for your time! Ur A.W.E.S.O.M.E !!!!
Topic archived. No new replies allowed.