samedi 4 janvier 2020

how to use functions that return a bool value?

I was writing a program to print 70 prime numbers (7 per row). I was required to define and use two functions isprime() and printprime. the program builds and runs but it doesn't print the prime numbers. I asked my friend for help , he knows more than me, but we couldn't figure out the problem.

#include "pch.h"
#include <iostream>
using namespace std;



bool isprime(int num)
 {
    int  x = 70, c, d = 0, h = 0, j = 1, y = 7;
    for ((j <= num); j++;)
    {
        c = num % j;
        if (c != 0)
        {
            h++;
            if (h == num - 1)
            {
                return true;

            }
            else
            {

                return false;
            }
        }

    }

}


void printprime(int x, int y)
{
    int  s, d = 0, h = 0, j = 0, num = 1;
    num = 1; x = 70; y = 7;

    for ((d < x); d += y;);
    {
        s = 0;
        cout << " " << endl;
        for ((s <= y); s++;)
        {


            if (isprime(num) == true)
            {
                cout << num;

                num++;
            }
            else
            {
                num++;
                s--;
            }

        }
    }

}


int main()
{
    int  x = 70, d = 0, h = 0, j = 0, y = 7, num = 1;
    num = 1; y = 7;

    printprime(x, y);

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire