Im trying to add a subtotal to my script but i cant think of a way , i tried adding another function to it so it would calculate the subtotal as i go but it wont happen ... .
Also i tried returnig the value of this function to another funtion
calculating what was need it and then returning to the main function to show the total but again wont happen
please help
#include <iostream>
#include <string>
using namespace std;
struct CodeInfo
{
string productCode;
unsigned int price; // or use double if you wish
};
int main()
{
CodeInfo items[3] = { {"rb38ssw500x500", 200},
{"rb38ssw600x600", 300},
{"rb38ssw700x700", 400}
};
do
{
string code;
cout << "Enter product code (or ctrl-D to exit): ";
cin >> code;
for (size_t i = 0; i < sizeof(items) / sizeof(CodeInfo); ++i)
{
if (code == items[i].productCode)
{
cout << "Price is: " << items[i].price << endl;
break;
}
}
} while (!cin.eof());
return 0;
}