Advertisement
Rapptz

SkillBuild.cpp

May 29th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. // Skill Build.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. #include <cctype>
  9. #include <sstream>
  10. #include <cstdlib>
  11.  
  12. void skillBuild(std::ostream& os,std::string name, int start, int end, int SP) {
  13.     for(int i = start; i<= end; i++) {
  14.         while(i<=end) {
  15.             int addition;
  16.             switch(SP) {
  17.             case 29: addition = 1;
  18.                 break;
  19.             case 28: addition = 2;
  20.                 break;
  21.             default: addition = 3;
  22.             }
  23.             SP += addition;
  24.             os << i << ". " << addition << " " << name << " (" << SP << ")\n";
  25.             i++;
  26.         }
  27.     }
  28. }
  29. int main() {
  30.     std::ofstream of;
  31.     std::string file;
  32.     std::stringstream ss;
  33.     std::cout << "Enter a file name: ";
  34.     getline(std::cin, file);
  35.     of.open(file);
  36.     if(!of.is_open()) {
  37.         std::cout << "File cannot be opened, exiting ";
  38.         std::cin.get();
  39.         exit(1);
  40.     }
  41.     do {
  42.         skillStart:
  43.             std::cout << "Starting level?: ";
  44.             int s, e, sp;
  45.             std::string input;
  46.             std::cin.clear();
  47.             getline(std::cin, input);
  48.             ss << input;
  49.             ss >> s;
  50.             ss.str("");
  51.             ss.clear();
  52.  
  53.             std::cout << "Ending level?: ";
  54.             getline(std::cin, input);
  55.             ss << input;
  56.             ss >> e;
  57.             ss.str("");
  58.             ss.clear();
  59.  
  60.             std::cout << "Skill name?: ";
  61.             std::string skillName;
  62.             getline(std::cin, skillName);
  63.            
  64.             std::cout << "Starting SP?: ";
  65.             getline(std::cin, input);
  66.             ss << input;
  67.             ss >> sp;
  68.             ss.str("");
  69.             ss.clear();
  70.  
  71.             skillBuild(std::cout, skillName, s, e, sp);
  72.             skillBuild(of,skillName,s,e,sp);
  73.  
  74.             std::cout << "Another skill? Y or N: ";
  75.             char retry;
  76.             std::cin >> retry;
  77.             toupper(retry);
  78.             std::cin.get();
  79.             if(!(retry != 'Y' || retry != 'N')) {
  80.                 std::cout << "Please enter a valid input: ";
  81.                 std::cin >> retry;
  82.                 toupper(retry);
  83.                 std::cin.get();
  84.             }
  85.             else if(retry == 'Y')
  86.                 goto skillStart;
  87.             else if(retry == 'N')
  88.                 of.close();
  89.     }
  90.     while(of.is_open());
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement