This program is supposed to get the multiples of whatever number the user inputs (x) until it reaches (y). All three loops function correctly but when used together we get get the first two loops but the third loop doesn't output. Also I would want to output each loop's output in a new line. My question is what can I do to make my outputs come out in three separate lines and why isn't my third loop outputting anything.
#include <iostream> #include <string> #include <cstdlib> using namespace std; bool error(const string & msg); int main(){ unsigned x, y; cout << "Give me a number you want the multiples of and give me the max limit: "; cin >> x >> y || error("Input Failure: "); if (x == 0) error("Input can't be 0"); unsigned increment = x; x = 0; while( x < y) { cout << x << ", "; x += increment; if (x > y) break; } cout << endl; // This was the other problem. I kept putting it inside the loop for(int x; x < y; x += increment){ cout << x << ", "; if (x > y) break; } cout << endl; // This was the other problem. I kept putting it inside the loop x = 0; // This is what originally was wrong do{ cout << x << ", "; x += increment; if ( x > y){ break; } }while (x < y); } bool error(const string & msg){ cout <<"Fatal error: " << msg << endl; exit(EXIT_FAILURE); }