Advertisement
Guest User

Untitled

a guest
May 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. struct currency {
  8. string currencyCode;
  9. double converison;
  10. };
  11.  
  12. void printCurrencies(currency *records, currency canadianRecords[], currency bitcoinRecords[], currency euroRecords[], currency usRecords[], currency poundrecords[]);
  13. string convertingToday(string &toBeConverted);
  14. string convertTo(string &convertingTo);
  15. void confirmConversion(string convertingTo, string toBeConverted );
  16. double convertCurrencies(string convertingTo, string toBeConverted, double amount, double &finalResult, currency *records, currency canadianRecords[], currency bitcoinRecords[], currency euroRecords[], currency usRecords[], currency poundrecords[] );
  17. double enterValues(string toBeConverted, double &amount);
  18.  
  19. currency records;
  20.  
  21. currency canadianRecords[4] = {{ "CAN - GBP:", 0.57}, {"CAN - USD:", 0.74}, {"CAN - ERO:", 0.67}, {"CAN - BIT:", 0.00031}};
  22. currency bitcoinRecords[4] = {{"BIT - GBP:", 1842.56}, {"BIT - USD:", 2386.12}, {"BIT - ERO:", 2133.80}, {"BIT - CAN:", 3207.06}};
  23. currency euroRecords[4] = {{"ERO - GBP:", 0.86}, {"ERO - USD:", 0.89}, {"ERO - BIT:", 0.00057}, {"ERO - CAN:", 1.50}};
  24. currency usRecords[4] = {{"USD - GBP:", 0.77}, {"USD - ERO:", 0.89}, {"USD - BIT:", 0.00042}, {"USD - CAN:", 1.34}};
  25. currency poundRecords[4] = {{"GBP - USD:", 1.29},{"GBP - ERO:", 1.16},{"GBP - BIT:", 0.00054}, {"GBP - CAN:", 1.74}};
  26.  
  27. int main() {
  28.  
  29. string toBeConverted = "ERROR";
  30. string convertingTo = "ERROR";
  31.  
  32. double amount;
  33. double finalResult;
  34.  
  35. convertingToday(toBeConverted);
  36.  
  37. convertTo(convertingTo);
  38.  
  39. confirmConversion(convertingTo, toBeConverted);
  40.  
  41. enterValues(toBeConverted, amount);
  42.  
  43. convertCurrencies(convertingTo, toBeConverted, amount, finalResult, &records, canadianRecords, bitcoinRecords, euroRecords, usRecords, poundRecords);
  44.  
  45. cout << amount << " to " << setprecision(6) << finalResult;
  46.  
  47. return 0;
  48. };
  49.  
  50. double enterValues(string toBeConverted, double &amount ){
  51.  
  52. cout << "Enter the amount of " << toBeConverted << " you would like to change: " << endl;
  53. cin >> amount;
  54.  
  55. return amount;
  56. }
  57.  
  58. double convertCurrencies(string convertingTo, string toBeConverted, double amount, double &finalResult, currency *records, currency canadianRecords[], currency bitcoinRecords[], currency euroRecords[], currency usRecords[], currency poundrecords[] ){
  59.  
  60. string conversionCode = toBeConverted + " - " + convertingTo;
  61.  
  62. double conversionMult;
  63.  
  64. for(int i(0); i <= 4; ++i){
  65. if(canadianRecords[i].currencyCode == conversionCode){
  66. conversionMult = canadianRecords[i].converison;
  67. }
  68. }
  69.  
  70. for(int i(0); i <= 4; ++i){
  71. if(bitcoinRecords[i].currencyCode == conversionCode){
  72. conversionMult = bitcoinRecords[i].converison;
  73. }
  74. }
  75.  
  76. for(int i(0); i <= 4; ++i){
  77. if(euroRecords[i].currencyCode == conversionCode){
  78. conversionMult = euroRecords[i].converison;
  79. }
  80. }
  81.  
  82. for(int i(0); i <= 4; ++i){
  83. if(usRecords[i].currencyCode == conversionCode){
  84. conversionMult = usRecords[i].converison;
  85. }
  86. }
  87.  
  88. for(int i(0); i <= 4; ++i){
  89. if(poundRecords[i].currencyCode == conversionCode){
  90. conversionMult = poundRecords[i].converison;
  91. }
  92. }
  93.  
  94. cout << "MULT IS: " << conversionMult;
  95.  
  96. finalResult = amount * conversionMult;
  97.  
  98. return finalResult;
  99. }
  100.  
  101. void confirmConversion(string convertingTo, string toBeConverted ){
  102.  
  103. string startOver;
  104.  
  105. cout << "You are converting " << toBeConverted << " to " << convertingTo << "." << endl << "Is this correct? (Enter Y to confirm, N to start over:" << endl;
  106. cin >> startOver;
  107.  
  108. if(startOver == "Y"){
  109. return;
  110. }
  111. else {
  112. convertingToday(toBeConverted);
  113.  
  114. }
  115.  
  116. }
  117.  
  118. void printCurrencies(currency *records, currency canadianRecords[], currency bitcoinRecords[], currency euroRecords[], currency usRecords[], currency poundRecords[]){
  119.  
  120. cout << "We can convert between the following:" << endl;
  121.  
  122. cout << "Canadian converisons:" << endl;
  123. for(int i(0); i <= 4; ++i){
  124. cout << canadianRecords[i].currencyCode;
  125. cout << endl;
  126. }
  127. cout << endl;
  128.  
  129. cout << "Bitcoin conversions:" << endl;
  130. for(int i(0); i <= 4; ++i){
  131. cout << bitcoinRecords[i].currencyCode;
  132. cout << endl;
  133. }
  134. cout << endl;
  135.  
  136. cout << "Euro conversions:" << endl;
  137. for(int i(0); i <= 4; ++i){
  138. cout << euroRecords[i].currencyCode;
  139. cout << endl;
  140. }
  141. cout << endl;
  142.  
  143. cout << "US Dollar conversions:" << endl;
  144. for(int i(0); i <= 4; ++i){
  145. cout << usRecords[i].currencyCode;
  146. cout << endl;
  147. }
  148. cout << endl;
  149.  
  150. cout << "British Pound conversions:" << endl;
  151. for(int i(0); i <= 4; ++i){
  152. cout << poundRecords[i].currencyCode;
  153. cout << endl;
  154. }
  155. cout << endl;
  156.  
  157. }
  158.  
  159. string convertingToday(string &toBeConverted){
  160.  
  161.  
  162. string startOver;
  163. string seeAll;
  164.  
  165. /*cout << "What currency are you converting from today?" << endl;
  166. cout << "You can convert between:" << endl << "GBP" << endl << "CAN" << endl << "BIT" << endl << "USD" << endl << "ERO" << endl;
  167. cin >> toBeConverted;
  168.  
  169. if(toBeConverted != "GBP" || "USD" || "CAN" || "BIT" || "ERO"){
  170. cout << "Looks like you entered the currency code wrong, pick again:" << endl;
  171. cin >> toBeConverted;
  172. }
  173.  
  174. cout << "To Confirm, you want to convert " << toBeConverted << " today?" << endl;
  175. cout << "Enter Y to continue or N to pick again:" << endl;
  176. cin >> startOver;
  177.  
  178. while(startOver != "Y"){
  179. cout << "What currency are you converting from today?" << endl;
  180. cout << "You can convert between:" << endl << "GBP" << endl << "CAN" << endl << "BIT" << endl << "USD" << endl << "ERO" << endl;
  181. cin >> toBeConverted;
  182. }
  183.  
  184. if(toBeConverted != "GBP" || "USD" || "CAN" || "BIT" || "ERO"){
  185. cout << "Looks like you entered the currency code wrong, pick again:" << endl;
  186. cin >> toBeConverted;
  187. }
  188.  
  189. cout << "To Confirm, you want to convert " << toBeConverted << " today?" << endl;
  190. cout << "Enter Y to continue or N to pick again:" << endl;
  191. cin >> startOver;*/
  192.  
  193. while(startOver != "Y"){
  194. cout << "What currency are you converting from today?" << endl;
  195. cout << "You can convert between:" << endl << "GBP" << endl << "CAN" << endl << "BIT" << endl << "USD" << endl << "ERO" << endl;
  196. cin >> toBeConverted;
  197.  
  198. while(toBeConverted != "GBP" && toBeConverted !="USD" && toBeConverted !="CAN" && toBeConverted !="BIT" && toBeConverted !="ERO"){
  199. cout << "Looks like you entered the currency code wrong, pick again:" << endl;
  200.  
  201. cin >> toBeConverted;
  202. }
  203.  
  204. cout << "To Confirm, you want to convert " << toBeConverted << " today?" << endl;
  205. cout << "Enter Y to continue or N to pick again:" << endl;
  206. cin >> startOver;
  207.  
  208. }
  209.  
  210. return toBeConverted;
  211. }
  212.  
  213. string convertTo(string &convertingTo){
  214.  
  215. string startOver;
  216. string seeAll;
  217.  
  218. while(startOver != "Y"){
  219. cout << "What currency are you converting to?" << endl;
  220. cout << "You can convert to:" << endl << "GBP" << endl << "CAN" << endl << "BIT" << endl << "USD" << endl << "ERO" << endl;
  221. cin >> convertingTo;
  222.  
  223. while(convertingTo != "GBP" && convertingTo !="USD" && convertingTo !="CAN" && convertingTo !="BIT" && convertingTo !="ERO"){
  224. cout << "Looks like you entered the currency code wrong, pick again:" << endl;
  225.  
  226. cin >> convertingTo;
  227. }
  228.  
  229. cout << "To Confirm, you want to convert " << convertingTo << " today?" << endl;
  230. cout << "Enter Y to continue or N to pick again:" << endl;
  231. cin >> startOver;
  232.  
  233. }
  234.  
  235. return convertingTo;
  236.  
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement