hey guys. i'm working on this project and i can't seem to get it figured out. there's a lot of steps involved, but i can't get any further right now because i cannot seem to figure out how to place values in an array.
the program should ask the user for a file name, open the file, and then put all the data from the file into an array, to start with.
the sample text file i've been given is called "input.txt" and consists of both letters and numbers:
Nut 10 1.99 0.53
Bolt 10 1.49 0.42
Screw 10 1.79 0.39
my code so far is this...
there are functions i have yet to write and variables i have yet to make use of, but you get the picture. the program itself compiles, but when i debug the values in ARRAY are something like "nut//////" and a bunch of random characters. any idea what i'm doing wrong??
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void SortName(char[]); // sorts list by item name
void SortProfit(char[]); // sorts list by profit
void SortPrice(char[]); // sorts list by price
void Buy (char[]); // adds one to a specific item chosen by user
void Display (char[]); // displays list as-is
void FindProfit (int,int,int); //finds profit of items
int main ()
{
char choice; //to hold user's menu choice
char item[81]; //to hold item user wishes to buy
char file[81];
char item_name[81];
const int NUM_ROWS = 3;
const int NUM_COLS = 4;
char ARRAY[NUM_ROWS][NUM_COLS];
unsigned int number_sold;
int ROWS, COLS;
float sales_price;
float item_cost;
ifstream ifile;
cout << "Enter the file name: ";
cin >> file;
ifile.open(file); //opens file
for (ROWS = 0; ROWS < NUM_ROWS; ROWS++)
{
for (COLS = 0; COLS < NUM_COLS; COLS++)
ifile >> ARRAY[ROWS][COLS]; // trying to input text into the array
}
if(!ifile) //to account for mistyped file name
{
cout <<"Could not open the file." << endl;
return 0;
}
return 0;
}