Thread: Help! Double-type array makes errors

  1. #1
    Unregistered
    Guest

    Unhappy Help! Double-type array makes errors

    In this program, I'm supposed to pull numerical data out of a file (which is arranged in rows and columns in the file), put it in a double array, and display the contents on the screen. Every time I try to declare a double-type array, I get a mysterious error message. Can someone tell me why? Here's my code:

    #include <iostream>
    #include <fstream>
    using namespace std;

    int main()
    {
    ifstream infile;
    double Acme_Calc[5][5], number;

    infile.open("A:\\Cs122sales.txt");

    infile.get(number);

    while (! infile.fail())
    {
    for (int rows = 0; rows < 5; rows++);
    {
    for(int columns = 0; columns < 5; columns++);
    {
    infile.get(number);

    Acme_Calc[rows][columns] = number;

    cout << Acme_Calc[rows][columns];
    }
    }
    }

    infile.close();

    return 0;
    }

  2. #2
    Unregistered
    Guest
    What error message are you getting?

  3. #3
    William
    Guest

    Question

    What error message are you getting?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    #include <iostream>
    #include <fstream> 
    using namespace std;
    
    int main() 
    { 
    ifstream infile; 
    double Acme_Calc[5][5], number; 
    
    infile.open("A:\\Cs122sales.txt"); 
    
    infile >> number; 
    
    for (int rows = 0; rows < 5; rows++) 
    { 
       for(int columns = 0; columns < 5; columns++) 
       {
          infile >> number; 
    
          Acme_Calc[rows][columns] = number; 
    
          cout << Acme_Calc[rows][columns]; 
       } 
    } 
    
    infile.close(); 
    
    return 0; 
    }

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    1
    This may sound like a lamer suggestion; after all, i didn't compile the code u offered, but i've experienced all sorts of problems using namespace std. Try your code without namespace, add what you need to, and see if that works.

    Good luck with it...

  6. #6
    Unregistered
    Guest

    Wink

    Oh, I see what I did wrong. I'm such a dork! Thanks a lot for the suggestions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  2. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. Errors that make no sense...
    By applescruff in forum C++ Programming
    Replies: 22
    Last Post: 03-04-2005, 05:44 PM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM