jeudi 29 mai 2014

Warning signs c++


Vote count:

-5





#include<iostream>
#include<string>
#include<ctime>
#include<cstdlib>
#include<fstream>
#include<iterator>
#include<iomanip>
#include<thread>
#include<cctype>
#include<vector>

using namespace std;

int primeNum(int numToPrime)
{
int count = 0;
for (int j = 1; j <= numToPrime; j++)
{
if (numToPrime % j == 0)
count++;
}

if (count == 2)
return numToPrime;
}

int main(int argc, char* argv[])
{
int someNum = 0;
int primeFac;

cout << "Please enter a number to get its prime factors: ";
cin >> primeFac;

int anotherTemp = primeFac;

cout << "Prime factorization of\n";
cout << anotherTemp << " = ";

if (primeFac == primeNum(primeFac))
cout << "1 * " << primeFac << endl;
else
{
for (int menNou = 2; menNou < anotherTemp; menNou++)
{
int countIt = 0;
while (primeFac % menNou == 0)
{
countIt++;
someNum = primeFac / menNou;
primeFac = someNum;
}

if (countIt != 0)
{
if (countIt == 1)
{
cout << menNou;
if (primeFac != 1)
cout << " * ";
}
else
{
cout << menNou << "^" << countIt;
if (primeFac != 1)
cout << " * ";
}
}
countIt = 0;
}
}
cout << endl;
return 0;
}


OUTPUT Please enter a number to get its prime factors: 1960 Prime factorization of 1960 = 2^3 * 5 * 7^2 Press any key to continue . . .


warning C4715: 'primeNum' : not all control paths return a value at compiling time, why is this? The program works fine but the warning scares me, please help....



asked 2 mins ago


1 Answer



Vote count:

0




You are getting this error because if count != 2, then you never hit a return statement in your primeNum function.



answered 13 secs ago





Aucun commentaire:

Enregistrer un commentaire