I am in a C++ class at my college and I am having trouble reading in strings and integers. I will post the instructions, text file, and my code and any help or shove in the right direction would be great. Thanks in advance.
Here is the problem:
Program must convert to and from US dollars. Ask user whether converting to or
from, then what other currency and what amount. Display all available currencies
and current rates. Calculate conversion with 5% bank fee deducted from final
amount.
Each currency is stored in two lines: the first line specifies the currency name, the second the
current exchange rates. The final line reads “STOP,” indicating that all records have been
processed.
In addition, you must:
• complete and turn in an algorithm describing your solution to this problem
• use proper spelling and grammar in the displayed text, and ensure that the user
experience is consistent and intuitive
Here is my code:
(I know it doesn't do everything it is supposed to do yet, but I just need help getting started.
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
|
#include<iostream>
#include<fstream>
using namespace std;
int main(){
// initialize variables
ifstream infile;
string country[5];
float conversion_f[5];
infile.open("rates.txt");
while(infile){
for(int i = 0; i < 5; i++){
infile >> country[i] >> conversion_f[i];
}
}
for(int i = 0; i < 5; i++){
cout << country[i] << " " << conversion_f[i] << endl;
}
return 0;
}
|
Here is the rates.txt file for the input:
Australian Dollars
0.96
British Pound Sterling
0.63
Canadian Dollars
1.00
Euro
0.74
Russian Rubles
30.01
STOP
------------------------
Here is what I'm having trouble doing... I want to read the strings and the floats in. Here is my output:
0
-1.46276e-05
3.98796e-34
-1.43755e-05
-1.4396e-05
-------------------------
I really don't know what I am doing wrong. :-/ Any help is greatly appreciated.