using arrays to store and retrieve multiple info from file HELP NEEDED PLEASE! :(

the program does not sort all the information into its respective variable array. and for some reason when i run the program and select option 1 by pressin'1'
it just prints the entire line in the program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
    //declaring the variables
    int i = 0;
    int Option = 0;
    string Date[2] = {};
    string RegionalCop[2] = {};
    char Typeog[2] = {};
    double Weightin[2] = {};
    double Weightout[2] = {};

    //asking the user to enter and option

    cout<<"Please choose an option:\n1.Option1\n2.Option2\n3.Option3\n4.Option4"<<endl;
   cin>>Option;


//association the object logs with the file named Data.txt
     ifstream Logs;
   Logs.open("Data.txt");

   if(!Logs.is_open()){cerr<<"Sorry file could not be opened";}//error message if file is not opened

   else{
               for ( ; i<3; i++){//for loop to read all the contents of the file

              //storing all the information in the appropriate array
             Logs>>Date[i];
             Logs.ignore(1);
             Logs>>RegionalCop[i];
             Logs.ignore(1);
             Logs>>Typeog[i];
             Logs.ignore(1);
             Logs>>Weightin[i];
             Logs.ignore(1);
             Logs>>Weightout[i];





//selection statement is user chooses option 1
if (Option == 1){
           //if user chooses option 1 all the contentes of the file will be place in a table under its category and then displayed on the screen
       cout<<"Date\tRegional Corporation\tTypeofGarbage\tweightin\tweightout"<<endl<<Date[i]<<endl<<RegionalCop[i];
       //cout<<" "<<endl;
       //cout<<" "<<endl;
       //cout<<""<<endl;
       //cout<<""<<endl;



 }//endif

break;

  }

             











    }



return 0;
        }




Last edited on
Contents of " Data.txt ":

November24,Tunapuna-Piarco,r,3000.00,2500.00
November25,Armia,g,4000.00,3500.00
Last edited on
Topic archived. No new replies allowed.