Question #36890

The machine holds six items numbered 1 through 6, with prices $1.25, $.75, $.90, $.75, $1.50, and $.75, respectively. The input to your program is an integer and a floating-point number representing an item number and a sum of money. If the money is enough to buy the item, your program should print: “Thank you for buying item X. Your change is Y.” If the money inserted is insufficient, then your program should say so. The following display give...

Expert's answer

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
double arr[6] = {1.25, 0.75, 0.90, 0.75, 1.50, 0.75};
int index;
double cost;
cout << "Input number of item: "; cin >> index;
cout << "Input your money: "; cin >> cost;
if(index > 6)
{
cout << "There is no such index" << endl;
return 0;
}
if(arr[index - 1] <= cost)
cout << "Thank you for buying item " << index << ". Your change is " << cost - arr[index - 1] << endl;
else
cout << "Not enough money for buying item " << index << endl;
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS