The following program is what I have so far. it reads from a pat.txt (patient list) and don. txt (doner list).
pat.txt
Patients 5
Androf O heart 24 2012
Blaren B kidney 35 2010
Cosmer AB heart 35 2007
Eralod O heart 53 2009
Forend B kidney 31 2003
don.txt
Donor 5
Zerk AB heart 20 2009
Rampe A kidney 31 2005
Darech B kidney 34 2008
Seo A kidney 26 2010
Yuio B kidney 26 2013
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "organANDbloodCOMPARE.h"
#include "RecentdonANDlongestpat.h"
#include "pat.h"
usingnamespace std;
struct Person{
string surname;
string BType;
string organ;
int age;
int year, ID, IDp;
} Patient[50], Donor[50];
int i;
int i1;
void compare(){
for (i = 0; i < 5; i ++){
for (i1 = 0; i1 < 5; i1++){
if (Patient[i].BType == Donor[i1].BType){
if (Patient[i].organ == Donor[i1].organ){
cout << "Compatible Match: " << Patient[i].surname << " "<< Donor[i1].surname << " " << Patient[i].BType << " and " << Donor[i1].BType << " Organ: " << Patient[i].organ << " " << Donor[i1].organ<< "\n";
}
}
//else
//cout << "\nNo match was found\n";
}
}
}
void certainblood(){
string letter;
cout << "Please choose a letter for bloodtype list: ";
cin >> letter;
if (letter == "A" | letter == "a"){
for (i = 0; i < 5; i++){
if (Patient[i].BType == "A")
cout << Patient[i].surname << "\n";
}
for (i1 = 0; i1 < 5; i1++){
if (Donor[i1].BType == "A")
cout << Donor[i1].surname << "\n";
}
}
if (letter == "B" | letter == "b"){
for (i = 0; i < 5; i++){
if (Patient[i].BType == "B")
cout << Patient[i].surname << "\n";
}
for (i1 = 0; i1 < 5; i1++){
if (Donor[i1].BType == "B")
cout << Donor[i1].surname << "\n";
}
}
if (letter == "AB" | letter == "ab" | letter == "Ab" | letter == "aB"){
for (i = 0; i < 5; i++){
if (Patient[i].BType == "AB")
cout << Patient[i].surname << "\n";
}
for (i1 = 0; i1 < 5; i1++){
if (Donor[i1].BType == "AB")
cout << Donor[i1].surname << "\n";
}
}
if (letter == "O" | letter == "o"){
for (i = 0; i < 5; i++){
if (Patient[i].BType == "O")
cout << Patient[i].surname << "\n";
}
for (i1 = 0; i1 < 5; i1++){
if (Donor[i1].BType == "O")
cout << Donor[i1].surname << "\n";
}
}
}
void longestpatient(){
int a;
int smallest = Patient[0].year;
for (i = 1; i < 5; i++){
if (Patient[i].year < smallest){
smallest = Patient[i].year;
a = i;
}
}
cout << smallest << " " << " Name of the patient: " << Patient[a].surname;
}
void longestpatrecentdon(){
//if ((Patient[i].BType == Donor[i1].BType) && (Patient[i].organ == Donor[i1].organ)){
int a, b;
int smallest = Patient[0].year;
for (i = 1; i < 5; i++){
if (Patient[i].year < smallest){
smallest = Patient[i].year;
a = i;
}
}
cout << smallest << Patient[a].surname;
int small = 3000;
for (i1 = 1; i1 < 5; i1++){
if (Donor[i1].year < small){
small = Donor[i1].year;
b = i1;
}
}
cout << " " << small << Donor[b].surname << "\n";
}
int main (int argc, char * argv[]){
ifstream myfile("pat.txt");
if (myfile.is_open()){
string numpat;
int num;
myfile >> numpat;
myfile >> num;
for (i = 0; num > i ; i++){
myfile >> Patient[i].surname;
myfile >> Patient[i].BType;
myfile >> Patient[i].organ;
myfile >> Patient[i].age;
myfile >> Patient[i].year;
Patient[i].ID = 472-i;
}
myfile.close();
}
ifstream myfile1("don.txt");
if(myfile1.is_open()){
string numpat1;
int num1;
myfile1 >> numpat1;
myfile1 >> num1;
for (i1 = 0; num1 > i1 ; i1++){
myfile1 >> Donor[i1].surname;
myfile1 >> Donor[i1].BType;
myfile1 >> Donor[i1].organ;
myfile1 >> Donor[i1].age;
myfile1 >> Donor[i1].year;
Donor[i1].ID = 297-i1;
}
myfile1.close();
}
/*if (argc >= 2){
if (atoi(argv[1]) == 1){
compare();
}
}*/
}
There are two problems with the code. The main problem is trying to figure out why compare is not outputing with the file ins. When i run it through eclipse, it runs fine, however when implementing the argc,argv for command line, it sees the compare function and goes to it, however data read from the files for some reason does not seem to want to be implemented within that function. Is there anyone here that could possibly see why thats the case? The second is that the longestpatrecentdon is outputing the opposite, that is, its outputting the most recent patient and longest donner. By recent and longest i mean years. Any suggestions would really help as I have spent countless hours trying to figure any possibilities as to why it dosen't work. The command line is of primary concern though.