Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Filename:
- // Author:
- // IQD:
- // Version:
- // Date:
- // Description:
- #include <iostream>
- #include "product.h"
- #include "lib.h"
- using namespace std;
- int main()
- {
- const int maxnum =5; //constant int stays the same throughout the program
- int selection =0;
- int idnumber =0;
- int counter =0;
- int print =0;
- product dataStore[maxnum]; //struct name, array name and array value
- do //do while loop
- {
- cout <<"Enter 1-6 for menu's, press 7 to exit program";
- cin >> selection; //reads in input done by user
- if (selection==1) //if selection = 1 then do something
- {
- cout << "Menu 1" <<endl; //endl means end line
- cout << "Please enter an ID number: ";
- cin >> dataStore[counter].id; //stores user input in array
- cout << "Please enter a price: ";
- cin >> dataStore[counter].price; //stores user input in array
- counter++; //adds 1 each time loop goes round
- }
- if (selection==2)
- {
- cout <<"Menu 2" <<endl;
- //insert loop here for part 6
- while (print<maxnum)
- {
- cout << dataStore[print].id <<endl; //these 2 lines print the data to the screen that was input in menu 1
- cout << dataStore[print].price <<endl;
- print++;
- }
- }
- if (selection==3)
- {
- cout <<"Menu 3" <<endl;
- }
- if (selection==4)
- {
- cout <<"Menu 4" <<endl;
- }
- if (selection==5)
- {
- cout <<"Menu 5" <<endl;
- }
- if (selection==6)
- {
- cout <<"Menu 6" <<endl;
- }
- }
- while(selection!=7);
- return 0;
- }
- struct product
- {
- int id;
- unsigned int price;
- };
- #include "lib.cpp"
- unsigned getPrice(product *dataStore);
- // Filename:
- // Author:
- // ID:
- // Version:
- // Date:
- // Description:
- unsigned getPrice(product *dataStore) //function code, variable type, function name, struct name, *array name
- {
- int compare =0;
- int idx =0;
- cout << "Please select an ID to search: " <<endl;
- cin >> compare;
- while(compare<7)
- {
- if (compare == dataStore[idx].id
- {
- compare=idx;
- cout << dataStore[compare].id << dataStore[compare].price;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment