Created
March 16, 2017 00:29
-
-
Save mattearly/cc63bb402f4ef4556b72b4124e17ac0c to your computer and use it in GitHub Desktop.
This file contains 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 <string> | |
#include <iostream> | |
// made to help with my printer and printing both sides | |
int main () { | |
std::cout << "This program prints numbers in sequence with comma seperated values as either even or odd\n"; | |
int choice; | |
while (choice == 0 && choice != 1 && choice != 2) { | |
std::cout << "1 for odd, 2 for even: "; | |
std::cin >> choice; | |
} | |
std::cout << std::endl; | |
int high = 0; | |
while (high == 0) { | |
std::cout << "ending point: "; | |
std::cin >> high; | |
} | |
std::cout << std::endl; | |
int low = 0; | |
while (low == 0) { | |
std::cout << "starting point: "; | |
std::cin >> low; | |
} | |
std::cout << std::endl; | |
switch (choice) { | |
case 1: | |
for (int i = low; i <= high; i++) { | |
if (i == high || i == high-1) { | |
if (i%2 == 1) { | |
std::cout << i << std::endl; | |
} | |
} else { | |
if (i%2 == 1) { | |
std::cout << i << ","; | |
} | |
} | |
} | |
break; | |
case 2: | |
for (int i = low; i <= high; i++) { | |
if (i == high || i == high-1) { | |
if (i%2 == 0) { | |
std::cout << i << std::endl; | |
} | |
} else { | |
if (i%2 == 0) { | |
std::cout << i << ","; | |
} | |
} | |
} | |
break; | |
default: std::cout << "switch error: check code\n"; return (1); break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment