For some reason my if statement in both my unionFunction and intersectFunction is setting the array equal to 1 rather then comparing it. I've tried to figure out whats wrong but nothing seems wrong to me. I appreciate any help.
Here is my program so far:
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <string>
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
#include <iomanip>
using std::setw;
// Global Arrays
int arrayA[100];
int arrayB[100];
int arrayC[100];
// Global Integers
int addDeleteNum = 0;
int addDeleteChange = 0;
// Global Char
char addDeleteStr;
// Global Call
void
unionFunction();
void intersectFunction();
void addDelete();
void driver();
void displayDriver();
// *******MAIN*********
int _tmain(int argc, _TCHAR* argv[])
{
// Set Random Seed
srand(0);
driver();
unionFunction();
displayDriver();
addDelete();
system("Pause");
}
// Or Statement Comparision
// If A or B Are 1 Set C To That Number
void unionFunction()
{
for (int i = 0; i <100; i++) {
if ((arrayA[i] = 1) || (arrayB[i] = 1)) {
arrayC[i] = 1;
}
else {
arrayC[i] = 0;
}
}
}
// And Statement Comparision
// If A and B Are Same Set C To That Number
void intersectFunction()
{
for (int i = 0; i <100; i++) {
if ((arrayA[i] = 1) && (arrayB[i] = 1)) {
arrayC[i] = 1;
}
else {
arrayC[i] = 0;
}
}
}
void addDelete()
{
cout << "Please Input the Array Letter (A or B): ";
cin.get(addDeleteStr);
cout << "Please Input the number you would like to add or delete: ";
cin >> addDeleteNum;
// Changes the values
switch(addDeleteStr) {
case 'a':
case 'A':
cout << "The number is currently: " << arrayA[addDeleteNum];
cout << "\nWhat would you like to change it to? ";
cin >> addDeleteChange;
arrayA[addDeleteNum] = addDeleteChange;
break;
case 'b':
case 'B':
cout << "The number is currently " << arrayB[addDeleteNum];
cout << "What would you like to change it to? ";
cin >> addDeleteChange;
arrayB[addDeleteNum] = addDeleteChange;
break;
default: cout << "Invalid input program exit";
break;
}
}
// Fills Arrays with Random 0 and 1
void driver()
{
int randNum = 0;
for (int i = 0; i < 100; i++) {
randNum = rand() % 2;
arrayA[i] = randNum;
}
for (int i = 0; i < 100; i++) {
randNum = rand() % 2;
arrayB[i] = randNum;
}
}
void displayDriver()
{
for (int i = 0; i < 100; i++) {
cout << setw( 5 ) << right << arrayA[i]
<< setw( 8 ) << left << arrayB[i]
<< setw(5) << left << arrayC[i]
<< ( 100 % 2 == 0 ? '\n' : '\t' );
}
}