Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <stdbool.h>
- int CountPrimes(int primes,int *pPrimesout);
- void DisplayReport(int primes,int factorial,int leapyear,int primesout,int factorialout,int leapyearout);
- int GetFactorial(int factorial, int *pFactorialout);
- bool IsLeapYear(int leapyear, int *pLeapyearout);
- bool IsPrime(int *isprime, int *pPrimeout);
- void PerformOperations(int primes, int factorial, int leapyear, int *pPrimesout, int *pFactorialout, int *pLeapyearout, int *pPrimecount);
- bool ValidateInput(int *pPrimes, int *pFactorial, int *pLeapyear);
- bool WithinRange(int input, int minRange, int maxRange);
- int main(int argc, char *argv[])
- {
- //int argv[3];
- int primes;
- int factorial;
- int leapyear;
- int primesout;
- int factorialout;
- int leapyearout;
- int primecount;
- ValidateInput(&primes, &factorial, &leapyear);
- PerformOperations(primes, factorial, leapyear, &primesout, &factorialout, &leapyearout, &primecount);
- // DisplayReport(primes, factorial, leapyear, primesout, factorialout, leapyearout);
- system("pause");
- return 0;
- }
- bool ValidateInput(int *pPrimes, int *pFactorial, int *pLeapyear)
- {
- int flag=1;
- printf("Project 3: ");
- scanf("%d %d %d", pPrimes, pFactorial, pLeapyear);
- printf("%d %d %d", *pPrimes, *pFactorial, *pLeapyear);
- if(flag=1)
- {
- flag = WithinRange(*pPrimes, 1, 1000);
- if(flag = 1)
- {
- flag = WithinRange(*pFactorial, 1, 12);
- if(flag = 1)
- {
- flag = WithinRange(*pLeapyear, 1, 4000);
- if(flag = 1)
- {
- flag = 1;
- }
- else
- printf("Data is invalid.");
- }
- else
- printf("Data is invalid.");
- }
- else
- printf("Data is invalid.");
- }
- return flag;
- }//end ValidateInput
- bool WithinRange(int input, int minrange, int maxrange)
- {
- int valid = 1;
- if(input < minrange || input > maxrange)
- {
- printf("The value is out of range. \n");
- valid = 0;
- }
- return valid;
- }//end WithinRange
- void PerformOperations(int primes, int factorial, int leapyear, int *pPrimesout, int *pFactorialout, int *pLeapyearout, int *pPrimecount)
- {
- IsPrime(primes, &pPrimesout);
- //GetFactorial(factorial, &pFactorialout);
- //IsLeapYear(leapyear, &pLeapyearout);
- //CountPrimes(primes, &pPrimecount);
- return 1;
- }
- bool IsPrime(int *isprime, int *pPrimeout)
- {
- int x;
- int primetest=1;
- printf("test%d",isprime);
- for(x=2; x<=floor(sqrt(*isprime)); x++)
- {
- if(*isprime%x==0)
- {
- primetest = 0; //number is not prime
- }
- }
- printf("%d",primetest);
- return primetest;
- }
- /*
- int GetFactorial(int factorial, int *pFactorialout)
- {
- int x = factorial;
- int c;
- int answer;
- for(c = 1, c<=x, c++)
- {
- answer = x*c;
- }
- return answer;
- }
- bool IsLeapYear(int leapyear, int *pLeapyearout)
- {
- if(leapyear%400 == 0 || (leapyear%100 != 0 && leapyear%4 == 0))
- {
- pLeapyearout=1;
- }
- else
- {
- pLeapyearout=0;
- }
- return pLeapyearout;
- }
- int CountPrimes(int primes,int *pPrimesout)
- {
- int num;
- for(num=1;num<=primes;num++)
- {
- pPrimesout=num;
- }
- return pPrimesout;
- }
- for(x = 3; x == primeIn; x++)
- {
- if(x%2 == 0)
- {
- break;
- }
- else
- {
- x = IsPrime(x);
- if(x == 1)
- {
- *pPrimeCount++;
- }
- }
- }
- }
- void DisplayReport(int primes,int factorial,int leapyear,int primesout,int factorialout,int leapyearout)
- {
- printf("Jason Gutel\n");
- printf("Project 3 - Simple Operations Program\n\n");
- printf("Operation Results:\n");
- printf("------------------\n\n");
- printf("Exactly %d prime numbers exist between 0 and %d", primesout, primes);
- printf("The value of %d! is %d", factorial, factorialout);
- if(leapyearout=1)
- {
- printf("The year %d is a leap year",leapyear);
- }
- else
- printf("The year %d is not a leap year",leapyear);
- }*/
Add Comment
Please, Sign In to add comment