Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // learningProject.cpp : main project file.
- #include "stdafx.h"
- #include <iostream>
- #include <stdio.h>
- #include <sstream>
- using namespace std;
- #define N '\n'
- void PrintInv(int i, int n, string inv[]){
- do{
- i = n;
- cout << "Item " << ++i << ": " << inv[n] << N;
- n++;
- }while(n<5);
- }
- int main(){
- start:
- int selection;
- int sel;
- int end = 0;
- int sel2;
- int tmpItem;
- string item1;
- string item2;
- string item3;
- string item4;
- string item5;
- string inv[5];
- int n=0;
- int i;
- //Prompts you for 5 inventory items
- do{
- cout << "What 5 items do you want to start with?"<< N;
- n=0;
- do {
- i = n;
- cout << "Item number " << ++i << ": ";
- cin >> inv[n];
- n++;
- }while (n<5);
- cout << "thank you for selecting your items." << N;
- item1 = inv [0];
- item2 = inv [1];
- item3 = inv [2];
- item4 = inv [3];
- item5 = inv [4];
- //menu for selecting your four choises.
- menu:
- selection = 0;
- system("pause");
- system("cls");
- cout << "Press '1' if you want me to read your items to you and continue, '2' if you want to re-select them, '3' if you want to change one item in your inventory, or '4' if you want to exit the application: ";
- cin >> selection;
- cout << N;
- //logic for menu. bad things happen in option 3.
- if (selection == 1) {
- end = 0;
- cout << "your selection is 1: " << N;
- system("pause");
- }
- else if (selection == 2){
- end = 1;
- cout << "your selection is 2" << N;
- system("pause");
- }
- else if (selection == 3) {
- system("cls");
- cout << "Press '1' if you want to read the inventory before changing, press anything else to just change it: ";
- cin >> sel;
- if (sel == 1){ //VERY BAD THINGS HAPPEN AFTER ENTERING IF STATEMENT
- PrintInv(i, n, inv);
- }
- cout << "---------------------------" << N;
- cout << "which inventory space do you want to change: ";
- cin >> sel2;
- cout << "What item do you want it to be: ";
- cin >> tmpItem;
- //PROBLEMS OCCUR AFTER THIS POINT
- inv[sel2] = tmpItem;
- cout << "selection changed!";
- goto menu;
- }
- else if (selection == 4){
- cout << "your selection is 4, good bye" << N;
- system("pause");
- exit(1);
- }
- }while (end != 0);
- //prints contents of array for option 1 in menu. No problems here.
- if ( selection == 1) {
- n=0;
- cout << "------------------------------------" << N;
- cout << "Here is what's in your inventory: " << N << N;
- PrintInv(i, n, inv);
- }
- //makes you restart if you enter in something other than 1-4 in menu.
- else {
- cout << "unexceptable, try again :V" << N;
- system("pause");
- system("cls");
- goto start;
- }
- cout << "other stuff..." << N;
- goto menu;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment