Skip to content

Instantly share code, notes, and snippets.

@mattearly
Created March 16, 2017 00:29
Show Gist options
  • Save mattearly/cc63bb402f4ef4556b72b4124e17ac0c to your computer and use it in GitHub Desktop.
Save mattearly/cc63bb402f4ef4556b72b4124e17ac0c to your computer and use it in GitHub Desktop.
#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