I am trying to read the data from the input file below and stop when the input file says "STOP". When I try to debug and print it to the screen, it prints something like a combination of the two variables... Here is my code:
/*******************************************************
* Program: Currency Converter
* Authors: Matthew Haggard and Adam Edwards
* Date Modified: 2013-02-04
*
* This program will convert from US dollars to some
* other currency with a bank fee deducted from the
* final amount.
*******************************************************/
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stdlib.h>
usingnamespace std;
struct Money{
string country;
string number; // convert from string to float later.
};
int main(){
// Initialize variables
int array = 5;
Money x[array];
ifstream infile;
infile.open("rates.txt"); // Open the file
for(int i = 0; i < array; i++){
getline(infile, x[i].country);
getline(infile, x[i].number);
// DEBUG
cout << x[i].country << " - " << x[i].number<< endl;
}
cout << x[0].country << endl << x[1].country << endl;
infile.close(); // Close the file
}
Here is my input file:
Australian Dollars
0.96
British Pound Sterling
0.63
Canadian Dollars
1.00
Euro
0.74
Russian Rubles
30.01
STOP
Here is my output:
- 0.96ian Dollars
- 0.63 Pound Sterling
- 1.00n Dollars
- 0.74
- 30.01Rubles
Australian Dollars
British Pound Sterling
Oh ok. Yea that makes alot of sense. I was using Windows and Ubuntu depending on where I was at. I ran the program on Windows and it worked just fine... Thanks alot for your help. I didn't even know that was a problem before now.