hey I was wondering if anyone out here can help me with C++ and also adding a loop at the end to be able to ask the user if they want to look up another part. attached is the string code i was given.
#include <fstream>
#include <iostream>
#include <string>
#include <iomanip.h>
using namespace std;
int main()
{
int item, quantity;
double price = 0.0;
const int SIZE = 6;
int valid_item[SIZE];
double valid_item_price[] = {0.89, 5.99, 7.50, 15.99, 19.50, 59.00};
int sub;
bool foundIt = false;
const string MSG_YES = "Item found";
const string MSG_NO = "Item not found";
ifstream data_in;
sub = 0;
data_in.open("input.txt");
while(!(data_in.eof()))
{
data_in >> valid_item[sub];
cout << valid_item[sub] << "Was stored in the array" << endl;
sub += 1;
}
data_in.close();
cout << endl;
cout << "Enter item number between 1 and 999: ";
cin >> item;
sub = 0;
cout << endl;
while((sub < SIZE) && (!(foundIt)))
{
cout << valid_item[sub] << " was compared" << endl;
if(item == valid_item[sub])
{
foundIt = true;
price = valid_item_price[sub];
}
sub += 1;
}
if(foundIt)
{
cout << endl;
cout << MSG_YES << endl;
cout << "Enter quantity: ";
cin >> quantity;
cout << setprecision (2)
<< setiosflags(ios::fixed | ios::showpoint);
cout << endl << quantity << " at $" << price << " each" << endl << endl;
cout << "Total: $" << quantity * price << endl <<endl;
}
else
cout << endl << MSG_NO << endl;
system("Pause");
return 0;
}