daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Apr 20th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*  Michael Brosh ID 304138738
  2.     Assignment 5, Ex. 1-6
  3.     Due date: 06.12.11  */
  4.  
  5.  
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. const char SIZE = 2;
  10.  
  11. void main()
  12.  
  13. {
  14.    
  15.     int rows, columns, letter_counter_1, index_1, letter_counter_2, index_2;
  16.     char mat[SIZE][SIZE] = {0}, letter;
  17.  
  18.     letter_counter_1 = 0;
  19.     letter_counter_2 = 0;
  20.  
  21.     cout << "Please enter 25 letters: \n\n";
  22.  
  23.     for (rows = 0 ; rows < SIZE ; rows++)
  24.     {
  25.         for (columns = 0 ; columns < SIZE ; columns++)
  26.         {
  27.             cin >> mat[rows][columns];
  28.         }
  29.     }
  30.  
  31.     cout << endl;
  32.  
  33.     cout << "Please enter a letter: \n\n";
  34.     cin >> letter;
  35.  
  36.     for (columns = 0 ; columns < SIZE ; columns++)
  37.     {
  38.         for (rows = 0 ; rows < SIZE ; rows++)
  39.         {
  40.             if ( (int)letter == (int)mat[rows][columns] )
  41.             {
  42.                 if (letter_counter_1 == 0)
  43.                 {
  44.                     if (letter_counter_1 == 0 && index_1 == 0)
  45.                         index_1 = mat[rows][columns];
  46.                     letter_counter_1++;
  47.                 }
  48.                 else if (letter_counter_2 == 0)
  49.                 {
  50.                     if (letter_counter_2 == 0 && index_2 == 0)
  51.                         index_2 = mat[rows][columns];
  52.                     letter_counter_2++;
  53.                 }
  54.                
  55.             }
  56.            
  57.         }
  58.  
  59.         if (letter_counter_1 > letter_counter_2)
  60.         {
  61.             letter_counter_2 = 0;
  62.             index_2 = 0;
  63.         }
  64.         else
  65.         {
  66.             letter_counter_1 = 0;
  67.             index_1 = 0;
  68.         }
  69.  
  70.     }
  71.  
  72.     if (index_1 == 0)
  73.         cout << index_2;
  74.     else
  75.         cout << index_1;
  76.    
  77.     cout << endl << endl;
  78.  
  79.     system("pause");
  80.  
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top