Created
October 29, 2013 09:05
-
-
Save NuckChorris/7211278 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
inline void phead (char section); | |
/** | |
* Give me asinine assignments, I give you asinine code. | |
* Now stop assigning glorified fizzbuzz. | |
**/ | |
int main | |
(void) | |
{ | |
// Declares the variables we use. | |
// the n prefix means number, since firstNum and secondNum were too long for | |
// my 80 char screen. even and odd are counters we use for summing. ten is | |
// used in the 1...10 loop, alpha for the alphabet loop. | |
int none, ntwo, even, odd, ten, alpha, err; | |
// Tri is misspelled try because that's a reserved word in C++ | |
bool tri = true; | |
// We goto the section to initialize our variables. | |
// I use goto for this because it uglies up the top of my function. | |
goto init; post_decl: | |
// Explain what we do... | |
std::cout << "Enter two integers. The first should be less than the second." | |
<< std::endl; | |
// ... and prompt for the variables | |
std::cout << "First: "; std::cin >> none; | |
std::cout << "Second: "; std::cin >> ntwo; | |
// check that they're good. | |
if (ntwo < none) { tri = true; goto plsinput; } | |
// First we print the numbers we got.. | |
std::cout << "(A) " << none << "; " << ntwo; | |
phead('B'); | |
// we save space in the registers by iterating over firstNum directly | |
for (;none < ntwo; ++none) { | |
// here we test if it's odd or even, and add it to the right places or | |
// print it accordingly. | |
if (none % 2 == 0) even += none; | |
else {std::cout << none << (none < ntwo-1 ? "; " : ""); | |
odd += pow(none, 2);} | |
} | |
// Section C | |
// we print the even sum now. | |
phead('C'); std::cout << even; | |
// Print the odd count | |
phead('E'); std::cout << odd; | |
// Move on to the ten | |
goto ten_section; | |
alphabet:// Section E | |
// print the alphabet by incrementing an integer and casting it to a char | |
// Old trick I learned in C ;) | |
phead('F'); while (++alpha <= 'Z') std::cout << (char)alpha; | |
goto die; | |
ten_section: | |
// Section D | |
phead('D'); while (ten++ < 10) // 1 ... 10, print them and their square | |
std::cout << ten << ", " << pow(ten, 2) << (ten+1 <= 10 ? "; " : ""); | |
// Move on to the Section F | |
goto alphabet; | |
init: | |
// Not really sure what this does, I just copied it off a forum. | |
none = ntwo = even = odd = err = tri = ((ten = 0xF) -= 15); | |
// We wanna start before A, since A needs to be the first iteration. | |
alpha = 'A'; alpha--; | |
plsinput: | |
// Try again :( | |
if (tri) std::cout << "You didn't read the rules, try again." << std::endl; | |
goto post_decl; | |
die: | |
// Some shells don't like if we don't end with a newline | |
std::cout << std::endl; | |
return err; | |
} | |
inline void phead | |
(char section) | |
{ | |
// This utility helps me print the section headers easier. | |
// And it doesn't slow anything down because it uses gcc's inline keyword! | |
std::cout << std::endl << "(" << section << ") "; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment