Not asking anyone to do the assignement or write the code....just need some pointers where to start.
The assignment asks us to declare an array of 5 structs that hold information read from a file, and to use a loop to print the information of every element in the array.
I'm totally lost on this. Do I open the file first using for example infile.open ("Myfile.txt)? Where is this myfile.txt? We have a bunch of example data, using a person's name, checking balance, savings balance and phone number.
Why do you need to loop it?
Is this the correct form for the array of 5 structs?
struct Info
{
char Name;
float Checking;
float Savings;
int Phone_Number;
} Bankinfo [5];
? I'm guessing you use 5 because it asks for 5 structs?
So, that is the struct. somewhere I'm going to call the Bankinfo array, and the information that gets put into the array will be from the myfile.txt ? Where and how to I put this information into the program? I've looked at several tutorials on infile etc and I've never seen how you actuall "store" the information, just how you open it.
I am also guessing that you need to loop it to bring the information into the array for each bank customer.
Very frustrating.
If someone could break it down for me I'd really appreciate it.
Here's what I have come up with so far...just trying to get the separate components up and then make them work togther. My compiler says my first bracket expects a declaration?
#include <iostream>
#include <fstream>
#include <ostream>
#include <istream>
usingnamespace std;
{ //here u are missing function sign or whatever, so put ( int func () )
ifstream infile;
char testinfo [51];
infile.open("myfile.txt");
if (!infile)
{cout<<"Not the right file"<<endl;
return (0);
}
else
{
cout<<"Enter the file name": // put semicolon (;) here not (:)
cin.get (testinfo,50);
infile.open (testinfo) // here u are missing semicolon to (;)
}
}
struct bankinfo {
char Name;
float Checking;
float Saving;
int phone_number;
} Info [5];
1. You forgot int main()
2. You already opened the file on line 13, why are you opening it again on line 26?
3. Could we see how the file is formatted? If the information is just spaced out in a human-readable format, you will be able to use infile >> Info[x].Name >> Info[x].Checking >> etc...
And for your question about "why loops?", well, it's much easier than writing statements over and over for each of the 5 array elements. And it's [art of the assignment :p