I am baffled by my code that sort of writes a graph:

I seem to have written in the wrong formula and it works better than with the right formula.Code:#include <iostream> #include <cstdlib> using namespace std; void drawgraph (int m, int c); int main() { int c; int m; cout<<"Welcome to Michael's Graph Plotter 2006"<<endl; while (1) { cout<<endl; cout<<"Please enter the gradient of your line (-5 to 5 and not 0): "; cin>>m; cin.ignore(); if (m >= -5 && m <= 5 && m != 0) { break; } else { continue; } } while (1) { cout<<endl; cout<<"Please enter the y intercept of you line (0 to 9): "; cin>>c; cin.ignore(); if (c >= 0 && c <= 9) { break; } else { continue; } } cout<<endl; cout<<"Press [ENTER] to see plot your graph..."; cin.get(); system("CLS"); drawgraph(m, c); cin.get(); return 0; } void drawgraph (int m, int c) { int y = 9; int x; int spaces; while (1) { spaces = 0; x = y/m + c; if (y >= 0 && y <= 9) { cout<<y; y--; while (1) { if(spaces == x) { cout<<"x"<<endl; break; } else { cout<<" "; spaces++; continue; } } if (y < 0) { break; } else { continue; } } } cout<<" 0123456789"<<endl; }

I know it has loads of problems and I know I have used while (1).