Hi good friends. I am stack here please help.
I want to write a program that prompts a user to enter details of up to 5 students
the displays the information on the screen.
Kindly help. I am new to C++
#include<iostream>
using namespace std;
int main ()
{
int i ;
int rn[5] ; // Roll Number
char name[99] ;
for (i = 0 ; i < 5 ; i++)
{
cout << endl << "Enter Name : " ;
cin >> name[i] ;
cout << endl << "Enter Roll No. : " ;
cin >> rn[i] ;
cout << endl ;
}
system ("pause") ;
return 0 ;
}
first of all please use code tags.... makes your code much more readable...
second you just copied my code. that's not going to work. Please try to figure out what is going on.
the struct is a type like int, double, long etc. Put it outside the main.
in the forloop a variable i is used. where is it declared? do you want every student to contain a element i?
the forloop increases the i variable to 5 then stops. i remains 5 and you try to print students[5], is this what you want?
I will help you, i will not give you the answer directly.
Jikax,
Thanks alot for your help.Its really enlightening me and making me think. I have take i, which the counter, and declared it as below
Student;
int i;
Student students[5];
for (i = 0 ; i < 5 ; i
The program runs without error but does not out put the 5 students I have entered. Yes I want to print the students[5]