Skip to content

Instantly share code, notes, and snippets.

@egroj97
Created May 3, 2018 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egroj97/3fc970e8e4ae59662cbaba248f1488c8 to your computer and use it in GitHub Desktop.
Save egroj97/3fc970e8e4ae59662cbaba248f1488c8 to your computer and use it in GitHub Desktop.
# include <fstream>
# include <iostream>
# include <string>
# include <iomanip>
using namespace std;
struct Items
{
string name;
unsigned ammount;
double cost;
};
int main(int argc, char const *argv[])
{
Items items[5];
ifstream reader;
double total = 0;
reader.open("Advanced25");
if (reader.fail())
return -1;
unsigned i = 0;
while (not reader.eof() and i < 5)
{
getline(reader, items[i].name, '#');
reader >> items[i].ammount;
reader.ignore();
reader >> items[i].cost;
i++;
}
cout << "NAME\tAMMOUNT\tCOST\n";
for (int i = 0; i < 5; ++i)
{
cout << setprecision(2) << fixed ;
cout << items[i].name << " => "
<< items[i].ammount << " => "
<< items[i].cost << endl;
total = total + (items[i].ammount * items[i].cost);
}
cout << "Total cost: " << total << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment