C++ struct Structure input with student data

Description

C++ struct Structure input with student data

#include <iostream>
using namespace std;
#include <string.h>
#include <iomanip.h>
#include <stdio.h>
void main()/*w  w w  .  j  a  va 2 s. co  m*/
{
   struct students
   {
      char name[25];
      int age;
      float average;
   } student1, student2;

   // Get data for two students.

   cout << "What is first student's name? ";

   gets(student1.name);

   cout << "What is the first student's age? ";

   cin >> student1.age;

   cout << "What is the first student's average? ";

   cin >> student1.average;

   fflush(stdin);    // Clear input buffer for next input.

   cout << "\nWhat is second student's name? ";

   gets(student2.name);

   cout << "What is the second student's age? ";

   cin >> student2.age;

   cout << "What is the second student's average? ";

   cin >> student2.average;

   // Print the data.
   cout << "\n\nHere is the student information you " << "entered:\n\n";
   cout << "Student #1:\n";
   cout << "Name:    " << student1.name << "\n";
   cout << "Age:     " << student1.age << "\n";
   cout << "Average: " << setprecision(2) << student1.average << "\n";
   cout << "\nStudent #2:\n";
   cout << "Name:    " << student2.name << "\n";
   cout << "Age:     " << student2.age << "\n";
   cout << "Average: " << student2.average << "\n";
   return;
}



PreviousNext

Related