Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code runs properly, but user input for # of students is ignored. The user should be able to enter any positive number of students, the

Code runs properly, but user input for # of students is ignored.

The user should be able to enter any positive number of students, the range being 1 to 50. No matter what I input, its ignored (ex. Enter 1, prompted for 50; Enter 1, prompted for 50;and so on).

I know it should be a simple fix but I don't see where I screwed up. How do I fix this?

(Note: C++, in Visual Studio 2017)

#include

#include

using namespace std;

struct Phone

{

int area_code;

int prefix;

int ph;

};

struct StudentPhoneRecord

{

string name;

Phone home, emergency, doctor;

};

//functions

void readNumStudents(StudentPhoneRecord a[]);

void readNameNumbers(StudentPhoneRecord a[]);

void displayOutput(StudentPhoneRecord a[]);

int main()

{

StudentPhoneRecord a[50];

readNumStudents(a);

readNameNumbers(a);

displayOutput(a);

cout << endl << endl;

system("pause");

return 0;

}

void readNumStudents(StudentPhoneRecord a[])

{

int i, num;

//get number of students

cout << "Enter number of students(must be a positive number less than or equal to 50) = ? ";

cin >> num;

}

void readNameNumbers(StudentPhoneRecord a[])

{

string dummy;

for (int i = 0; i<50; i++)

{

cout << "Please enter the information for student " << i + 1 << endl;

cout << "" << endl;

cout << "Name: ";

cin.ignore();

getline(cin, a[i].name);

cout << "" << endl;

cout << " Home Phone :" << endl;

cout << " Area Code : ";

cin >> a[i].home.area_code;

cout << " Prefix: ";

cin >> a[i].home.prefix;

cout << " Suffix: ";

cin >> a[i].home.ph;

cout << " Emergency Phone :" << endl;

cout << " Area Code : ";

cin >> a[i].emergency.area_code;

cout << " Prefix: ";

cin >> a[i].emergency.prefix;

cout << " Suffix: ";

cin >> a[i].emergency.ph;

cout << " Doctor Phone :" << endl;

cout << " Area Code : ";

cin >> a[i].doctor.area_code;

cout << " Prefix: ";

cin >> a[i].doctor.prefix;

cout << " Suffix: ";

cin >> a[i].doctor.ph;

cout << "" << endl;

}

}

void displayOutput(StudentPhoneRecord a[])

{

for (int i = 0; i < 50; i++)

{

cout << "Students Phone report is:" << endl;

cout << a[i].name << endl;

cout << "Home:\t\t" << a[i].home.area_code << "-" << a[i].home.prefix << "-" << a[i].home.ph << endl;

cout << "Emergency:\t" << a[i].emergency.area_code << "-" << a[i].emergency.prefix << "-" << a[i].emergency.ph << endl;

cout << "Doctor:\t\t" << a[i].doctor.area_code << "-" << a[i].doctor.prefix << "-" << a[i].doctor.ph << endl;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago