A better design is to have the prime( ) function only return the 0 or 1 indicating primeness. Let main( ) be responsible for the actual printing of the number and * if appropriate.
Your for loop is only printing the values that are prime. A little modification will fix that:
for( numb = 5; numb <= 49; numb += 2 )
{
if( prime(numb) ==1 )
cout << "* ";
cout << numb << " " << sumsq( numb ) << " " << sumcb( numb ) << endl;
}
If you work on using a more consistent indenting style, the fact that the cout line was the action of the if condition would be more apparent, and then you'd see why you were only printing the primes. Don't be afraid to use { } to show blocks, even when not strictly needed. And put some blanks between operands and operators. It does aid readability.
Val
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Double check all your { } pairs, make sure you've not left an open set in main( ). That could lead the compiler to thinking you're trying to declare a function inside a function.
Also, it helps if you post the exact message.
Your prime function should be just as you originally posted, with the cout << line removed. An else is not needed.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Double check all your { } pairs, make sure you've not left an open set in main( ). That could lead the compiler to thinking you're trying to declare a function inside a function.
The easiest way to do this is to learn how to format your code correctly.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944