iipq

vv

Apr 9th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <bitset>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. char letter = ' ', playAgain = 'y';
  10. string word = " ";
  11.  
  12. cout << "\t**Text To Binary Convertor**\n\n";
  13.  
  14. while (playAgain == 'y'){
  15.  
  16. cout << "Please enter a character, word, or phrase: ";
  17.  
  18. getline (cin, word, '\n');
  19.  
  20. cout << "\nThe binary value for " << word << " is \n";
  21.  
  22. for (unsigned int wordPosition = 0; wordPosition < word.size(); ++wordPosition){
  23.  
  24. letter = word[wordPosition];
  25.  
  26. bitset <8> binary(letter);
  27.  
  28. cout << binary;
  29. }
  30.  
  31.  
  32. cout << "\n\nWould you like to try again? (y/n)";
  33.  
  34. cin >> playAgain;
  35.  
  36. if (playAgain != 'y'){
  37. cout << "\n\nExiting program.";
  38. playAgain = 'n';
  39. }
  40. cin.ignore();
  41. }
  42.  
  43.  
  44.  
  45. return 0;
  46. }v
Advertisement
Add Comment
Please, Sign In to add comment