Hi, I'm writing a program that will test integer values to find out its factors and whether it is prime. It will run a batch file with 3 integer values as data within the file. Using cin >>, the program will pull the first two values that will serve as the range of integer values to be tested. The third integer value will be used as the specified number of factors we are testing for.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
// Input: Data from a batch file containing 3 integer values. The first and
// second values represent the range of values to be tested. The first value
// will be less than or equal to the second value. The third integer value
// represents the number of factors being tested for within the range of
// values INCLUDING the first two integer values within the batch file.
// Output: A list of numbers in the range that have the number of factors
// specified by the third integer, the number of numbers with the specified
// factor count, the number of prime factors found within the range and finally
// the average of the prime numbers found.
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
int first; // First integer value within range of tested values
int last; // Last integer value within range of tested values
int numoffactors; // Number of specified factors being tested for
int counter1; // This is the first loop control variable
int counter2; // This is the second loop control variable
int counter3; // This is the variable to store the number of factors
// that the given number has
int counter4 = 0; // This is the variable to store the number of integer
// values that have the specified factors
int prime = 0; // This the variable to store number of prime numbers
int primavg; // This is the average of all prime factors
int primesum; // This is the sum of all prime factors
cout << "\n";
cout << "Jesse Yapi - Assignment #6 - Section #1003" << endl;
cout << "\n";
cin >> first >> last >> numoffactors;
cout << "Numbers with at least " << numoffactors << " between " << first;
cout << " and " << last << ":" << endl;
for (counter1 = first, counter1 <= last, counter1 = counter1+1)
{
counter3 = 0;
for (counter2 = 1, counter2 < counter1, counter2++)
{
switch (counter1 % counter2)
{
case 0:
counter3++;
if (counter3 >= numoffactors)
counter4++;
cout << counter1 << endl;
break;
}
}
if (counter3 == 2)
prime++;
primesum = primesum + counter1;
else
cout << endl;
}
cout << counter4 << " numbers with at least " << numoffactors
<< " factors found" << endl;
cout << "Prime factors found: " << prime << endl;
cout << fixed << showpoint << setprecision(4);
cout << "Average of primes: " << primesum/prime << endl;
return 0;
}
|
I'm very new to this but every time I try to compile my program I get these errors:
In function âint main()â:
error: expected â;â before â)â token
error: expected primary-expression at end of input
error: expected â;â at end of input
error: expected primary-expression at end of input
error: expected â)â at end of input
error: expected statement at end of input
error: expected â}â at end of input
Also, I'm sure there is a much more efficient method to doing this. I'd love your insight. PLEASE HELP ME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!