Thread: Anyone know how to use this formula?

  1. #1
    Registered User
    Join Date
    Sep 2007

    Anyone know how to use this formula?

    address of the first record in the array + (account number - 1000) * sizeof(int).

    I am supposed to read this file into 4 separate arrays. And, be able to request a user-entered account number and display the corresponding name and account balance. This is all I come up with so far, but not really sure how to use that formula.

    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    #include <cstdlib>
    #include <string>
    using namespace std;
    int main()
    	string filename = "bank.dat";
    	const int CUSTOMERS=5;
    	int i=0, acctNum[CUSTOMERS];
    	string firstName[CUSTOMERS], lastName[CUSTOMERS];
    	float balance[CUSTOMERS];
    	ifstream inFile;
    		cout<<"\nThe file named "<<filename<<" was not successfully opened"
    			<<"\nPlease check that the file currently exists."
    	cout<<"\nThe file has been successfully opened for reading."
    	cout<<"\nEnter the account number for the customer you are looking for: "<<endl;
    	return 0;

    this line also gives me this error: error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'int [5]' (or there is no acceptable conversion)


  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    You will need to use a loop to read each entry from the file [and I presume that the file looks something like this:
    1001 John Smith 183.75
    1002 Adam Boone 3291.40
    Assuming you were successfull in reading five items at a time, the file would need to look like this:
    1001 1002 1003 1004 1005
    John Adam ...
    Smith Boone ... 
    183.75 3291.40 ...
    I doubt this is the actual format of the file.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2002
    The error message means that the >> operator isn't (and can't be)
    overloaded for the purpose of reading into an array itself, such
    as you try to do with this:


    as acctNum, firstname, lastname and balance are all arrays,
    or the address of the first element of an array, depending how used.
    You should read into any given element of the array like this:


    since acctNum[x], firstName[x],lastName[x] and balance[x] are all
    individual objects of type int, string, string, and double respectively.
    Use a loop to get all the different elements of each array
    stored in the file in place.

    The formula looks like it might be used to calculate an offset, but
    that's a guess.
    You're only born perfect.

  4. #4
    Registered User
    Join Date
    Nov 2007
    well wut this formula seems to do : it gives you the size of memory this information uses in ur vector wich seem to be a vector of int...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zeller's Formula
    By unejam2005 in forum C++ Programming
    Replies: 6
    Last Post: 11-14-2005, 09:48 PM
  2. how to change char to formula
    By kosong in forum C Programming
    Replies: 2
    Last Post: 06-09-2003, 04:31 AM
  3. Math formula (js -->C++)
    By Demon1s in forum C++ Programming
    Replies: 20
    Last Post: 05-02-2003, 05:22 AM
  4. Need help with this formula -b/2a..Please read.
    By foofoo in forum C Programming
    Replies: 4
    Last Post: 06-04-2002, 11:59 PM
  5. Formula string conversion
    By Gr3g in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 08:28 PM