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 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <ctime>
using namespace std;
// Function Prototypes ****************************************************
void findMinmax (int & min, int &max);
int randNum (int min, int max);
void dispArr ();
void calcTot (int & totaleven, int & totalodd, int a[]);
// main function **********************************************************
int main ()
{
srand(time(NULL));
int min, max, numone;
int totaleven = 0;
int odd = 0;
int counter = 0;
int arr [25];
findMinmax(min, max);
cout << "total even is " << totaleven << endl; //doesnt change (stays at 0)
cout << "total odd is: " << odd << endl; //doesnt change (stays at 0)
do
{
numone = randNum(min, max);
cout << "the random number is: " << numone << endl;
arr[counter] = numone;
cout << "the counter is: " << counter << endl;
counter++;
}while (counter<26);
cout << "total even is " << totaleven << endl; //doesnt change (stays at 0)
cout << "total odd is: " << odd << endl; //CHANGES INTO RANDOM NUMBER???
calcTot(totaleven, odd, arr);
cout << "Please press enter once or twice to continue...";
cin.ignore().get();
return EXIT_SUCCESS;
}
void findMinmax(int & min, int &max)
{
do
{
cout << "Enter the Minimum (higher than 0)" << endl;
cin >> min;
cout << "Enter the Maximum (lower than 501)" << endl;
cin >> max;
}while ((min<=0)||(max>=501));
}
int randNum (int min, int max)
{
int numone;
numone = min + rand()%(max - min + 1);
return numone;
}
void calcTot(int & totaleven, int & totalodd, int a[])
{
int count = 0;
cout << "total even is " << totaleven << endl;
cout << "total odd is: " << totalodd << endl;
do
{
if(a[count]%2 == 0)
{
totaleven=+a[count];
cout << "the total of even number is:" << totaleven << endl;
count++;
}
else
{
totalodd+=a[count];
cout << "the total of odd number is:" << totalodd << endl;
count++;
}
}while (count<26);
cout << "total of even is: " << totaleven;
cout << "total of odd are: " << totalodd;
}
|