posted by .

Can anyone help me with my c++ program? Its a program I have to write using structs and arrays and i'm stuck. If anyone can help can you post back and I'll show you what i've got and maybe you can tell me why its not working correctly.

I can try. I have not done much outside of Visual Basic. But maybe I can figure out your problem.

My assignment is to initialize an array of structs using the data from an input file. To get the input file the user must input the name of the file.Theres more i need to add but i cant get this to work so i havent even tried the other stuff.
Well this is what ive got so far...

#include <iostream>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

const int ARRAY_SIZE = 40;

struct studentType
string firstName;
int id;
int testScore;

void getData(ifstream& inData, studentType sList[], int& listSize);
void printList(const studentType sList[], int listSize) ;

int main()
int student_count;
studentType studentList [ARRAY_SIZE];

ifstream inData;

char inputFile[40];

cout << "Please enter the name of the input file you would like to use"
<< " and press enter"
<< endl;
cin >> inputFile;


if (!inData)
cout << "The input file does not exist."
<< endl;


getData(inData, studentList, student_count);
printList(studentList, student_count);

system ("pause");
return 0;

void getData(ifstream& inFile, studentType sList[], int& listSize)
int i = 0;
cout << "getData\n";

if ( !inFile)
cout << " no File\n ";

inFile >> sList[0].firstName >> sList[0].id
>> sList[0].testScore ;

while (inFile)
inFile >> sList[0].firstName >> sList[0].id
>> sList[0].testScore ;
listSize = i ;
cout << "listSize = " << listSize <<endl <<endl <<endl;

void printList(const studentType sList[], int listSize)

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. English

    1. I watch documentaries when I feel down. (What is the meaning of 'feel down'?
  2. programming

    write a program that maintains two parallel arrays. after th arrays have been loaded the program should behave as a login screen prompting for username and password. the program should respond three output messages. if username does …
  3. finance

    A company wants to invest in a new advertising program. Using the NPV method of capital budgeting, determine the proposal’s appropriateness and economic viability with the following information: • The new program will increase …
  4. C++ Programming

    Video Game Player Program Write a program to do the following. In main declare a Player Name Array and a Score Array. Declare the size of the arrays to be 100. In the InputData function input the player name and score into the arrays …
  5. Programming

    Write a pseudocode program that asks the user for an integer between 1 and 12. The program is to calculate the times table for that number. So for example, if the user enters a 2, then the program has to calculate 2x1 and display the …
  6. Math

    Write a program in C to find a root of a given equation using Secant Method. Perform five iterations to obtain the smallest positive root of the equation f(x) = sin x + 2tanx. Verify your answer with the program written by you. Please …
  7. C#

    Create three array of type double. Do a compile-time initialization and place 10 different values in tow of the arrays. Write a program to store the product of the two arrays in the third array. Produce a display using the MessageBox …
  8. programming

    a program displays the name of fruits that are sorted from the arrays(program that sort five names)
  9. CIS

    Create three arrays of type double. Do a compile-time initialization and place different values in two of the arrays. Write a program to store the product of the two arrays in the third array. Write a method to display the contents …
  10. C++

    // Program: name of program // Author: your name // Date Written: date you began writing the program /* Abstract: Brief description of the program */ Include in-line comments in the body of your program. You can convert temperature …

More Similar Questions