cannot achieve desired output (cout) from a C++ loop -


thanks last night able program computing input properly, have trouble formatting output properly. problem:

my program should print "is prime" on lines prime numbers. prints on ever line this:

http://oi42.tinypic.com/30igbvq.jpg

i cannot life of me figure out why doing this, of functions should work.

stack need again!

#include <iostream> using namespace std;   void primecheck(int x); // proto void countr(int rnm, int lnm); // proto  void prime(int x) // function finds prime factors of number. { int lastr = 2; int count = 0; while (lastr < x) {      if (x % lastr == 0)     {         cout << x << " " << lastr << "*";         x /= lastr;     }     else         ++lastr; } primecheck(x); // calls check if number prime, "is prime" }   void console(int rnum, int lnum) // prompts user 2 numbers stores     answers { cout << "please enter 2 numbers "; cin >> rnum; cin >> lnum; countr(rnum, lnum); }  void countr(int rnm, int lnm) // function loops prime function until        numbers computed {  int = rnm; do{     prime(i);     i++; } while (i <= lnm);     return; }   int main() // main, calls console pauses when finished { int e = 0; int r = 0;     console(e, r);     system("pause"); } void primecheck(int x) // checks see if number prime. if counter equal 2 number prime. { int counting = 0; (int = 1; <= x; a++) {     if (x %a == 0)     {         counting++;     } }  if (counting == 2) {     cout << x << " prime " << endl; } else {     cout << x << endl; } } 

you're using /= operator in prime(). that's assignment operator , modifying value of x, making x prime whenever primecheck() called.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -