Hello all. I'm a first year C++ student and I'm going cross-eyed trying to figure out what's wrong with this code that I've started on. I need a little help understanding parallel arrays.
The program is supposed to let a user input their Student ID. From there, it will either find it and show the student their information OR it will say "not found" if it's not found in the array.
My problem is that any number I input, will only show the first index of the 3 parallel arrays. I was told to use a boolean (found = false or true) but that didn't work either. I've made such a mess, but I cant figure out how to relate the user input to the ID array. Also, I have to figure out how to relate that array to the matching array. I'm pretty sure it's a simple fix but I'm not seeing it at all.
Please help.. *beg*
Thank you for any and all tips that you can give me.
Madison Alexis
#include <stdafx.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
// Array Declarations -- hard code
int ID[5] = { 1234, 3225, 4413, 6438, 1358};
float Ex[5] = { 81.21F, 74.53F, 90.50F, 74.81F, 62.31F};
float Lab[5] = { 83.57F, 82.80F, 84.15F, 93.67F, 72.20F};
const int n = 5;
int StudentID;
bool Found = false;
float SemGrade;
char CloseP;
int k;
// Code to match student ID with input
for(k = 0; k < n; k++)
{
cout << "Enter your Student ID: ";
cin >> StudentID;
if(ID[k] == StudentID)
Found = true;
else
Found = false;
cout << "None found";
cout << endl;
//Semester grade calculation
SemGrade = 0.6*Ex[k] + 0.4*Lab[k];
// Display student information
cout << "ID: " << StudentID << "\n";
cout << "Exam Average = " << Ex[k] << "\n";
cout << "Lab Average = " << Lab[k] << "\n";
cout << "Semester Grade = " << SemGrade << "\n";
if (SemGrade >=90 && SemGrade <=100){
cout << "Letter grade = A" << endl << endl;
}
else if (SemGrade >=80 && SemGrade <=89){
cout << "Letter grade = B" << endl << endl;
}
else if (SemGrade >=70 && SemGrade <=79){
cout << "Letter grade = C" << endl << endl;
}
else if (SemGrade >=60 && SemGrade <=69) {
cout << "Letter grade = D" << endl << endl;
}
else {
cout << "Letter grade = F" << endl << endl;
}
// Ends the program.
cout << "Enter any value to close console.";
cin >> CloseP;
return 0;
}
}