Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <string>  // I added the string lib so you can now use stirngs with std::string
  4.  
  5. using std::cout;
  6. using std::cin;
  7. using std::endl;
  8. using std::system;
  9.  
  10. /*
  11. I have declared a function here so that we can use it in a function call in main(), if
  12. we dont declare it here the function call wont know it exists because the function is below it.
  13. The other option is to move the entire function above main(), then the function call within
  14. main() will know it exists as it only looks above, not below.
  15. */
  16. // RULE: C++ Code can only look up, it can't look down!
  17. bool DoTheDance(int Runs);
  18.  
  19. int main()
  20. {
  21.     SetConsoleTitle( TEXT("NigraCalQ"));
  22.  
  23.     /*
  24.     Here I want to keep replaying the function until the function tells me not to repeat any
  25.     more. So what I've done is to create a bool (true/false) variable and assign the result
  26.     of the function to it. If the function returns false the 'while' loop will stop. 'While'
  27.     loops can only continue if it's argument is true, and they will continue to repeat until
  28.     it's argument is false.
  29.  
  30.     I've also created a new int variable that will count how many times the function is run.
  31.     In the 'while' loop after the function call I have called the variable and put a '++' after
  32.     it. This is a simple way to say to the variable 'increase by 1!'.
  33.  
  34.     The last change you will notice is the 'if' statement in the loop. All this does is check if
  35.     this is the first time the loop has been run, if it has then it will just put a new line in
  36.     the console to spread things out a bit and make it a bit easier to read.
  37.     */
  38.     bool Dancing = true;
  39.     int Runs = 0;
  40.     while (Dancing)
  41.     {
  42.         if (Runs > 0) cout << "\n";
  43.         Dancing = DoTheDance(Runs);
  44.         Runs++;
  45.     }
  46.  
  47.     system ("pause>nul"); // Google told me about this one.
  48.  
  49.     return 0;
  50. }
  51.  
  52. /*
  53. Here is the implementation of the function that we have declared above.
  54. */
  55. bool DoTheDance(int Runs)
  56. {
  57.     int Nig1;
  58.     int Nig2;
  59.     int DiffDeter;
  60.     int DifResult;
  61.     int BigNig;
  62.     int LilNig;
  63.        
  64.     cout << "We have run this process " << Runs << " times before!\n";
  65.     cout << "Enter the age of 2 them their niggras: ";
  66.     cin >> Nig1 >> Nig2;
  67.  
  68.     if (Nig1);
  69.  
  70.     {
  71.         if ( Nig1 != Nig2);
  72.         cout << "You dun got 2 different aged niggras! Sheeeeeeeit..." << endl;
  73.         DifResult = (Nig1 - Nig2);
  74.        
  75.         if (DifResult < 0)
  76.             DiffDeter = (DifResult * -1);
  77.         else
  78.             DiffDeter = (DifResult * 1);
  79.        
  80.         cout << "Nogras be ";
  81.         cout << DiffDeter;
  82.         cout << " yeeaz apart." << endl;       
  83.     }
  84.     else
  85.     {
  86.         if ( Nig1 > Nig2)
  87.             BigNig = (Nig1 - Nig2);
  88.         else
  89.             BigNig = (Nig2 - Nig1);
  90.         cout << "That first there niggra is ";
  91.         cout << BigNig;
  92.         if (Nig1 > Nig2)
  93.             cout << " years older";
  94.         else
  95.             cout << " years youger";
  96.         cout << " than that second niggra." << endl;
  97.     }
  98.  
  99.     /*
  100.     Now to see if the user wants to continue. If the user does want to continue then return
  101.     the result of 'true', if not then return the result of false. Simples!
  102.     */
  103.     std::string ContinueTheDance;
  104.     cout << "Do you still wanna dance? (y/n): ";
  105.     cin >> ContinueTheDance;
  106.  
  107.     if (ContinueTheDance == "y")
  108.         return true;
  109.     else
  110.         return false;
  111.        
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement