I am working on this project for a class. I have input the students last name, first name, student ID and three test scores. I have to make the first step a function that stores the data into an array. Inside this array it is also going to give the letter grade. it's supposed to look like the following except all lined up evenly:

Last Name First Name Id Test 1 Test 2 Test 3 Grade
Ant Adam 56789 65 72 68 D
Doe Jane 67890 54 64 52 F
Mix Tom 45678 98 83 74 B
Nerd Bobby 12345 95 96 99 A
Sunday Billy 34567 75 65 82 C
Thumb Tom 23456 87 93 77 B

The first problem I'm running up against is that my input code for the last name, first name etc is not stopping when I press the n key.

I think I need an if else statement that will stop if the user types 'N' but keep going if the user types 'Y' but since I only have 6 sets of data to put in the array. I'm fairly new to C++ and the two or three people I have spoken to in person about this project can't believe the project that I'm doing here for an entry level C++ class. I'm excited to learn though

Here is the code I have right now:

#include<iostream>
#include<string>


using namespace std;


int main()
{


int i = 0;
string studentInfo[7][7];
char inputDone = 'y';






for(i=0; inputDone = 'y'; i++)
{
cout << "Please Input student's first name : " << endl;
cin >> studentInfo[i][0];


cout << "Please Input student's last name : " << endl;
cin >> studentInfo[i][1];


cout << "Please Input student's  ID Number : " << endl;
cin >> studentInfo[i][2];


cout << "Please Input student's Test 1 Grade : " << endl;
cin >> studentInfo[i][3];


cout << "Please Input student's Test 2 Grade : " << endl;
cin >> studentInfo[i][4];


cout << "Please Input student's Test 3 Grade : " << endl;
cin >> studentInfo[i][5];


cout << "Are there anymore student grades to enter? (y/n)" <<endl;
{
    
cin >> inputDone;
}






}

Very common mistake in for loop:

for(i=0; inputDone == 'y'; i++)

did u get this!!

Very common mistake in for loop:

for(i=0; inputDone == 'y'; i++)

did u get this!!

Don't blame him for making a mistake, everyone makes mistakes (me too), let me explain:
If you write for(i=0; inputDone [B]=[/B] 'y'; i++) with one '=' sign then you're doing an assignment to a variable, which in this case means that everytime when the loop has run one time variable inputDone gets assigned value 'y'.
The assignment operator '=' always returns the assigned value (in this case the assigned value is 'y' every time), which means that if the assigned value was anything other than zero (or some value which will be implicitly converted to zero), the condition in the loop will be evaluated to true which means the loop will be running non-stop (otherwise the condition will be evaluated to false, which means the loop won't run, but this isn't the case here).
So how do we get over this?
Well you probably wanted to compare the value in variable inputDone with 'y', so you'll have to use the '==' operator: for(i=0; inputDone [B]==[/B] 'y'; i++) .

Remember: If you want to compare two variables or two values (or a variable and a value) you use the '==' operator, if you want to assign a value/variable to a variable, you use the '=' operator

Don't blame him for making a mistake, everyone makes mistakes (me too), let me explain:

I was not blaming anyone I was just addressing a common mistake which anyone can make.

Come on Man!!

I put the code posted above and added in for(i=0; inputDone == 'y'; i++) What it's doing now is not letting me choose y/n just going to the "press any key" line. What do I need to do to change this? I tried putting in for(i=0; inputDone == 'n'; i++) because I really have no idea, this isn't my strongpoint in life.

Thanks for the help so far though

I don't know where you're talking about, with me it works fine, could it be that you did something wrong?

cout << "Are there anymore student grades to enter? (y/n)" <<endl;
{
    
cin >> inputDone;
}

remove the red bracket in your code.

Well, I didn't want to redunantly post my code so I'll post towards the end of my code:

cout << "Please Input student's Test 3 Grade : " << endl;
cin >> studentInfo[i][5];

cout << "Are there anymore student grades to enter? (y/n)" <<endl;
{
     for(i=0; inputDone == 'y'; i++)
     cin >> inputDone;
}
     system ("pause");
     return 0;
}
}
}

I tried changing the place where I have that for statement right now. I tried taking the curly braces out, error. Tried moving it right below the cout statement cout << "Are there anymore student grades to enter? (y/n)" <<endl; error stating that dev expected declaration before '}'

I can post the code as I have it now where I'm getting the error if that would help

ok, I got it to work so that if I input 'n' in the screen it closes the program down, which is not what I want it to do ultimately. However, when I press 'y' it does not let me input more data, I can press enter to my heart's content and it won't do anything, but after I press 'y' any key I press closes the program. any thoughts?

#include<iostream>
#include<string>

using namespace std;

int main()
{

    int i = 0;
{
    string studentInfo[6][7];
    char inputDone = 'y';
    
    
    
    for(i=0; inputDone == 'y'; i++)
{
    cout << "Please Input student's last name : ";
    cin >> studentInfo[i][0];
    
    cout << "Please Input student's first name : ";
    cin >> studentInfo[i][1];
    
    cout << "Please Input student's  ID Number : ";
    cin >> studentInfo[i][2];
    
    cout << "Please Input student's Test 1 Grade : ";
    cin >> studentInfo[i][3];
    
    cout << "Please Input student's Test 2 Grade : ";
    cin >> studentInfo[i][4];
    
    cout << "Please Input student's Test 3 Grade : ";
    cin >> studentInfo[i][5];
    
    cout << "Are there anymore student grades to enter? (y/n)";

    for(i=0; inputDone == 'y'; i++)
    cin >> inputDone; 

    cin.get();
    return 0;   
}
}
}

Hmm, you should have posted the full code in your last post. Anyways, here is your code with the done modification. This must be working:

#include<iostream>
#include<string>
using namespace std;
int main()
{
    int i = 0;
    string studentInfo[7][7];
    char inputDone = 'y';

    for (i=0; inputDone == 'y'; i++)//notice the change here
    {
        cout << "Please Input student's first name : " << endl;
        cin >> studentInfo[i][0];

        cout << "Please Input student's last name : " << endl;
        cin >> studentInfo[i][1];

        cout << "Please Input student's  ID Number : " << endl;
        cin >> studentInfo[i][2];

        cout << "Please Input student's Test 1 Grade : " << endl;
        cin >> studentInfo[i][3];

        cout << "Please Input student's Test 2 Grade : " << endl;
        cin >> studentInfo[i][4];

        cout << "Please Input student's Test 3 Grade : " << endl;
        cin >> studentInfo[i][5];

        cout << "Are there anymore student grades to enter? (y/n)" <<endl;
        cin >> inputDone;
    }//end of loop

}//end of main

I see what I did. I put the for statement inside the for loop.

You can use the following while loop as well for the same pupose.

#include<iostream>
#include<string>
using namespace std;

int main(){
	int i = 0;
	string studentInfo[7][7];
	char inputDone = ' ';
	bool check = true;
while(check)
		{
		system("CLS");
		cout << "Please Input student's first name : "; 
		cin >> studentInfo[i][0];


		cout << "Please Input student's last name : " ;
		cin >> studentInfo[i][1];


		cout << "Please Input student's  ID Number : ";
		cin >> studentInfo[i][2];


		cout << "Please Input student's Test 1 Grade : ";
		cin >> studentInfo[i][3];


		cout << "Please Input student's Test 2 Grade : ";
		cin >> studentInfo[i][4];


		cout << "Please Input student's Test 3 Grade : ";
		cin >> studentInfo[i][5];


		cout << "Are there anymore student grades to enter? (y/n)";		    
		cin >> inputDone;
		
		(inputDone=='y')?check=true:check=false;

	}
}

But i will recommend u to use classes if we are talking about C++.
as u can see here..

#include <iostream>
#include <string>
using namespace std;
class Student{
private:
	char lastName[50]; 
	char firstName[50]; 
	int id; 
	int test1; 
	int test2; 
	int test3; 
	char grade;
public:
	Student(char *fName=NULL,char *lName=NULL,int idkey=0,int t1=0,int t2=0,int t3=0,char g = ' '){
		strcpy_s(firstName,fName);
		strcpy_s(lastName,lName);
		id = idkey;
		test1 = t1;
		test2 = t2;
		test3 = t3;
		grade = g;
	}
// May add Other Function .......................................
};

void main(){
	//Student st1(all detail will be here);	
}

Feel free to contact any time...regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.