c++ - Is there a way to display my prime number list output in 2 columns? -


i taking first programming class , first time posting. have been able find on site previous projects when got stuck, , hope doing right.

i have completed program below display prime number between 0 , 100 intro c++ class.

the thing kinda bothers me in single column, wanted go step , make nice , display numbers in couple columns. tried using "\t", can't work right. ideas on might add code? think using array have not covered in class , i'm not supposed use them yet.

the challenge was:

"use isprime function wrote in programming challenge 21 in program stores list of prime numbers 1 through 100 in file."

and here code:

#include <iostream> #include <iomanip> #include <cstdlib> #include <string> using namespace std;  bool isprime(int);  int main() { static int num1=0;  cout<<"listed below prime numbers 1 through 100."<<endl<<endl<<endl;  {     num1++;     if (isprime(num1))     {     cout<<num1<<endl;     } } while (num1<100);  cout<<endl;  return 0; }  bool isprime(int num1) {  bool primenum=true; (int i=2;i<num1;i++) {     if (num1%i==0)     {         primenum=false;     } } return primenum; } 

thanks in advance input,

find cout.width()

#include <iostream> #include <iomanip> #include <cstdlib> #include <string> using namespace std;  bool isprime(int);  int main() {     static int num1 = 0;      cout << "listed below prime numbers 1 through 100." << endl << endl << endl;      int column = 0; // column variable     int width = 10; // column width size          {         num1++;         if (isprime(num1))         {             cout.width(width); // set column's width             cout << num1;              if (column == 1) { // if prime number printed in column 2                 cout << endl; // add new line                 column = 0; // set column first             }             else {                 column++; // increase column index             }         }      } while (num1<100);      cout << endl;      return 0; }  bool isprime(int num1) {     // error: isprime returns true when num1 1 or 2. change     if (num1 == 1 || num1 == 2) return false;      // isprime     bool primenum = true;     (int = 2; i<num1; i++)     {         if (num1%i == 0)         {             primenum = false;         }     }     return primenum; } 

Popular posts from this blog