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; 
}

Oh sorry. I needed an explanation on how to link my data file to this C++ project too.

What do you mean by 'link'? And please put your code in [ code ] [ /code ] tag... Give me a headache when read your code...

Anyway, you open a file using data_in.open("input.txt"); in the code. Just change the name of the file in order to read the file content.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.