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 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/******************
Errors:
putting size in the for loop results in the loop not executing
enabling findCompanyIndex returns a compiler error
showData only shows company5 for the name (data is correct)
******************/
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
//function prototypes
void getData(string [], double [][4], int);
void showData(string [], double [][4], int size);
int findCompanyIndex(string, string[], int);
int main(){
//initialize variables
string name[4], userName;
double data[4][4];
int counter = 0;
int size = 5;
//gets and shows data
getData(name, data, counter);
showData(name, data, counter);
cout << "Enter the name of a company: ";
cin >> userName;
//findCompanyIndex(userName, name, size);
//system stuff
system("pause");
return 0;
}
void getData(string name[], double data[][4], int names){
ifstream inputFile;
//opening file
inputFile.open("Data.txt");
for (int row = 0; row < 5; row++){
for (int col = 0; col < 5; col++){
if (col == 0){
inputFile >> name[col];
//debugging
cout << setw(4) << name[col] << " ";
}
else{
inputFile >> data[col][row];
//debugging
cout << setw(4) << data[col][row] << " ";
}
}
//new line before each iteration, creating a clean look
cout << endl;
}
cout << endl;
inputFile.close();
}
void showData(string name[], double data [][4], int size){
for (int row = 0; row < size; row++){
for (int col = 0; col < size; col++){
if (col == 0){
cout << name[col] << " ";
}
else{
cout << data[col][row] << " ";
}
}
cout << endl;
}}
int findCompanyIndex(string userName, string name, int names2){
int total = 5;
for (int col = 0; col < 5; col ++){
if (userName == name){
name[col];
cout << "Yes!";
}
else{}
}
return total;
}
|