Store and display information using structure in CPP

#include <iostream>
using namespace std;

struct student
{
    char name[50];
    int roll;
    float marks;
} s[6];

int main()
{
    cout << "Enter information of students: " << endl;

    for(int i = 0; i < 6; ++i)
    {
        s[i].roll = i+1;
        cout << "Roll number " << s[i].roll << ":" << endl;

        cout << "Enter name: ";
        cin >> s[i].name;

        cout << "Enter marks: ";
        cin >> s[i].marks;

        cout << endl;
    }

    cout << "Displaying Information: " << endl;


    for(int i = 0; i < 6; ++i)
    {
        cout << "\nRoll number: " << i+1 << endl;
        cout << "Name: " << s[i].name << endl;
        cout << "Marks: " << s[i].marks << endl;
    }

    return 0;
}

Leave a comment

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started