Guest User

Untitled

a guest
Jan 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. // Filename:
  2. // Author:
  3. // IQD:
  4. // Version:
  5. // Date:
  6. // Description:
  7.  
  8.  
  9. #include <iostream>
  10. #include "product.h"
  11. #include "lib.h"
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.  
  17.     const int maxnum =5;   //constant int stays the same throughout the program
  18.  
  19.     int selection =0;
  20.     int idnumber =0;
  21.     int counter =0;
  22.     int print =0;
  23.     product dataStore[maxnum];    //struct name, array name and array value
  24.  
  25.  
  26.     do   //do while loop
  27.     {
  28.    
  29.         cout <<"Enter 1-6 for menu's, press 7 to exit program";
  30.         cin >> selection;  //reads in input done by user
  31.        
  32.         if (selection==1)   //if selection = 1 then do something
  33.         {
  34.             cout << "Menu 1" <<endl;  //endl means end line
  35.             cout << "Please enter an ID number:  ";
  36.             cin >> dataStore[counter].id;  //stores user input in array
  37.             cout << "Please enter a price: ";
  38.             cin >> dataStore[counter].price;  //stores user input in array
  39.             counter++;   //adds 1 each time loop goes round
  40.  
  41.         }
  42.         if (selection==2)
  43.         {
  44.             cout <<"Menu 2" <<endl;
  45.             //insert loop here for part 6
  46.             while (print<maxnum)
  47.             {
  48.  
  49.                 cout << dataStore[print].id <<endl;    //these 2 lines print the data to the screen that was input in menu 1
  50.                 cout << dataStore[print].price <<endl;
  51.  
  52.                 print++;
  53.             }
  54.  
  55.  
  56.  
  57.            
  58.            
  59.  
  60.         }
  61.         if (selection==3)
  62.         {
  63.             cout <<"Menu 3" <<endl;
  64.         }
  65.         if (selection==4)
  66.         {
  67.             cout <<"Menu 4" <<endl;
  68.         }
  69.         if (selection==5)
  70.         {
  71.             cout <<"Menu 5" <<endl;
  72.         }
  73.         if (selection==6)
  74.         {
  75.             cout <<"Menu 6" <<endl;
  76.    
  77.         }
  78.     }
  79.     while(selection!=7);
  80. return 0;
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.    
  88.            
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. struct product
  97. {
  98.     int id;
  99.     unsigned int price;
  100. };
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. #include "lib.cpp"
  112.  
  113. unsigned getPrice(product *dataStore);
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. // Filename:
  123. // Author:
  124. // ID:
  125. // Version:
  126. // Date:
  127. // Description:
  128.  
  129.  
  130. unsigned getPrice(product *dataStore)   //function code, variable type, function name, struct name, *array name
  131. {
  132.     int compare =0;
  133.     int idx =0;
  134.  
  135.  
  136.     cout << "Please select an ID to search:  " <<endl;
  137.     cin >> compare;
  138.  
  139.     while(compare<7)
  140.     {
  141.        
  142.         if (compare == dataStore[idx].id
  143.         {
  144.             compare=idx;
  145.             cout << dataStore[compare].id << dataStore[compare].price;
  146.        
  147.         }
  148.     }
  149.  
  150.  
  151.  
  152.  
  153.  
  154. return 0;
  155. }
Add Comment
Please, Sign In to add comment