Guest User

Untitled

a guest
Jul 9th, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. // learningProject.cpp : main project file.
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include <stdio.h>
  5. #include <sstream>
  6. using namespace std;
  7.  
  8. #define N '\n'
  9.  
  10. void PrintInv(int i, int n, string inv[]){
  11.     do{
  12.         i = n;
  13.         cout << "Item " << ++i << ": " << inv[n] << N;
  14.         n++;
  15.     }while(n<5);
  16. }
  17.  
  18. int main(){
  19.     start:
  20.     int selection;
  21.     int sel;
  22.     int end = 0;
  23.     int sel2;
  24.     int tmpItem;
  25.     string item1;
  26.     string item2;
  27.     string item3;
  28.     string item4;
  29.     string item5;
  30.     string inv[5];
  31.     int n=0;
  32.     int i; 
  33.    
  34.     //Prompts you for 5 inventory items
  35.     do{
  36.         cout << "What 5 items do you want to start with?"<< N;
  37.         n=0;
  38.         do {
  39.             i = n;
  40.             cout << "Item number " << ++i << ": ";
  41.             cin >> inv[n];
  42.             n++;
  43.         }while (n<5);
  44.         cout << "thank you for selecting your items." << N;
  45.        
  46.         item1 = inv [0];
  47.         item2 = inv [1];
  48.         item3 = inv [2];
  49.         item4 = inv [3];
  50.         item5 = inv [4];  
  51.  
  52.         //menu for selecting your four choises.
  53.         menu:
  54.         selection = 0;
  55.         system("pause");
  56.         system("cls");
  57.         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: ";
  58.         cin >> selection;
  59.         cout << N;
  60.        
  61.         //logic for menu. bad things happen in option 3.
  62.         if (selection == 1) {
  63.             end = 0;
  64.             cout << "your selection is 1: " << N;
  65.             system("pause");
  66.         }
  67.         else if (selection == 2){
  68.             end = 1;
  69.             cout << "your selection is 2" << N;
  70.             system("pause");
  71.         }
  72.         else if (selection == 3) {
  73.             system("cls");
  74.             cout << "Press '1' if you want to read the inventory before changing, press anything else to just change it: ";
  75.             cin >> sel;
  76.             if (sel == 1){   //VERY BAD THINGS HAPPEN AFTER ENTERING IF STATEMENT
  77.                 PrintInv(i, n, inv);
  78.             }
  79.             cout << "---------------------------" << N;
  80.             cout << "which inventory space do you want to change: ";
  81.             cin >> sel2;
  82.             cout << "What item do you want it to be: ";
  83.             cin >> tmpItem;
  84.         //PROBLEMS OCCUR AFTER THIS POINT
  85.             inv[sel2] = tmpItem;
  86.             cout << "selection changed!";
  87.             goto menu;
  88.         }
  89.         else if (selection == 4){
  90.             cout << "your selection is 4, good bye" << N;
  91.             system("pause");
  92.             exit(1);
  93.         }
  94.  
  95.     }while (end != 0);
  96.    
  97.     //prints contents of array for option 1 in menu. No problems here.
  98.     if ( selection == 1) {
  99.         n=0;
  100.         cout << "------------------------------------" << N;
  101.         cout << "Here is what's in your inventory: " << N << N;
  102.         PrintInv(i, n, inv);
  103.     }
  104.    
  105.     //makes you restart if you enter in something other than 1-4 in menu.
  106.     else {
  107.         cout << "unexceptable, try again :V" << N;
  108.         system("pause");
  109.         system("cls");
  110.         goto start;
  111.     }
  112.    
  113.     cout << "other stuff..." << N;
  114.     goto menu;
  115.     return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment