Hi everyone. I writing a program that opens the file "plants.txt" ( see below) and then reads "plants.txt" into two arrays(name and price). The file is then sorted from lowest to highest in price.
I have 3 errors on program in the second while loop( see below) with comments for more detail.
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>;
usingnamespace std;
int main ()
{
string name; //declaring variables
int price;
ifstream theFile("plants.txt"); // filename
while(theFile >> name >> price) // opens the file
{ cout << name<< price << endl;
}
int ArrayOne[58]; // defining array size
int ArrayTwo[58];
int i, size = 0;
while (!feof("plants.txt")) /* First error. "plants.txt" Error: argument of type "const Char" is incompatiable with parameter of type "FILe" so i am not sure what to replace "plants.txt" with*/
{
fscanf("plants.txt", " %d %d", &name, &price); // same issue as the one above with "plants.txt"
ArrayOne[size] = name; // FINAL error: no suitable conversion function from "std::string" to int exists
ArrayTwo[size] = price;
size++;
}
for (i = 0; i<size; i++) { // sorts the data
printf("ArrayOne[%d] = %d, ArrayTwo[%d] = %d\n",
i, ArrayOne[i], i, ArrayTwo[i]);
}
system ("pause");
return (0);
}