0

ok I need this program to run the first and last names and the grades of 20 people. how would i set up a for-loop to do this.

#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std; 
const int MAX = 3;
struct Person 
{
 string Firstname, Lastname;
 int grade;
 Person()
 {
  Firstname="No name assigned";
  Lastname="No name assigned";
  grade = -1;
 }
 Person (string l, string f, int g)
 {
 Firstname = f;
 Lastname =l;
 grade = g;
 }
};
int main()
{
 int grade;
 string strFirstname, strLastname;
 cout<<"Enter person's first name: ";
 getline(cin, strFirstname);
 cout<<"Enter person's last name: ";
 getline(cin, strLastname);
 cout  <<"Enter the grade: ";
 cin>>grade;
 cin.ignore();
 Person p1(strLastname, strFirstname, grade);
 cout <<"The person's name is: "
  <<p1.Lastname<<", "<<p1.Firstname<<endl;
 cout <<"The grade is: "
  <<p1.grade<<endl;
 return 0;
}
3
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by WaltP
0

I need the program to ask for the users last name, first name and grade 20 times. where do i put the for loop.

0

FOR loop is fine. Think about it... What do you need to do each and every time the loop runs? That's what goes in the loop.

Please indent your code. It's hard to read without proper indentation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.