simple string info program

Hi, I am a new one in to CPP Programming
I am trying to create a software which does the following


Data of 3-4 students should be given/ declared in the code like his NAME, AGE, GRADE, ROLL NO etc.

When program starts, it should ask to enter the student name
User enters the student name
Program shows the Data of the students and pauses with a prompt

if user enters q, program quits

if user enters anything else, it searches through the pre-declared students records, if matched a student name, it displays the record and stops with prompt again

if user input is not q but also does not matches any student, program say, STUDENT NOT FOUND and stops with prompt again

I have been trying my best, but unable to get it done, please help

Should use IF and/ or LOOP
Here's how it works. You try to write the program. Every time you bump into something you can't solve, you come here, post the code you have so far, and we'll help you. No one here will just do your homework for you.
OK, here is what I have done so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#include <iostream>
using namespace std;

int main(){
    //string student[5][50];
    // Let's say this array variable store student information like this
    // Name, Father Name, Class, Roll No
    string studentname[50];
    string student[5][50] = {
                            {"John", "Smith", "5th", "15"}, 
                            {"Michael", "Angelo", "3rd", "13"},
                            {"Stone", "David", "6th", "21"},
                            {"Simon", "Peter", "4th", "17"}
                            };
    cout<< "Please Enter the Student Name: ";
    cin ( studentname, 50, '\n' );  // getting error on this line
    cout<< "Your Name is: " << student[1][0]; 
    cin.get();   
}

I am stuck on line 3 from below
OK, I just got a little further, please check and help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include <iostream>
using namespace std;

int main(){
    // Let's say this array variable store student information like this
    // Name, Father Name, Class, Roll No
    char studentname[50];
    int studentFound = 0;
    int studentID = 0;
    string studentData[5][50] = {
                            {"John", "Smith", "5th", "15"}, 
                            {"Michael", "Angelo", "3rd", "13"},
                            {"Stone", "David", "6th", "21"},
                            {"Simon", "Peter", "4th", "17"}
                            };

    cout << "Please Enter the Student Name: ";
    cin >> studentname;
    /*
    for ( studentID = 0; studentID < 10; x++ ) {
                     if(studentname == studentData[studentID][0]){
                                    studentFound = 1              
                                    }
                     studentID++;
                     } 
    */
    cin.get();
    }
and Finally, I was able to do it
here is how it works

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

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

int searchString(string A[],int size, string target)
{
int j;
	for(j=0; j < size; j++){
		if(A[j] == target)
		return j;
	}
	return j= -1;
}

int main ( )
{
	string target = "";
	string sName[5] = { "Ali", "Asad", "Aslam", "Akram","Ahsan" };
	string fName[5] = { "Ali's Father", "Asad's Father", "Aslam's Father", "Akram's Father","Ahsan's Father" };
	int age[5] = {15,18,21,19,23};

	cout << "\n Please enter a Student Name, or enter q to exit: ";
	getline(cin, target);

	while(true){
		if (target == "q")
		{return 0;}
		else
		{
		int j = searchString( sName, 5, target );

		if (j== -1){
		cout<< "\n Student Not Found";
		}
		else{
		cout << "\n\n\n Student Name: \t" << sName[j];
		cout << "\n Father Name: \t" << fName[j];
		cout << "\n Age: \t" << age[j];
		}
		cout << "\n\n\n Please enter a Student Name, or enter q to exit: ";
		getline(cin, target);
		}
	}
	return 0;
}

Topic archived. No new replies allowed.