I need to write program that will compare 2 binary numbers and return the result
I wrote this code using XOR, but idk how to improve my code, so for example 100101 and 101001 will return a < b. Can you help me fix this please?
string a,b;
la = a.length();
lb = b.length();
int x = 0;
if (la == lb)
{
for (int i = 0; i < la; i++)
{
if (a[i]^b[i] == 1)
{
if(a[i] > b[i])
x++;
}
else {x--;}
}
if (x > 0)
cout << a << " > " << b << endl;
if (x < 0)
cout << a << " < " << b << endl;
if (x == 0)
cout << a << " = " << b << endl;
}
Guess this would be better
Here no need to iterate th whole string unless they are equal.
Just find the first '1' and the one which has 1 before will be bigger.
As simple as that
int main()
{
string a,b;
cin>>a>>b;
size_t aLoc=-1,bLoc=-1;
do
{
aLoc = a.find("1",aLoc+1);
bLoc = b.find("1",bLoc+1);
if(aLoc<bLoc)
{
cout<<a<<">"<<b;
return 0;
}
else if(aLoc>bLoc)
{
cout<<a<<"<"<<b;
return 0;
}
}while(aLoc==bLoc && aLoc!=string::npos);
cout<<a<<"="<<b;
return 0;
}
Edit:
aLoc give the position of 1 in first string, and bLoc for 2nd string
Lets take 1 exmaple
a = 10111000;
here first aLoc = 1 as the first '1' is at position 1
b = 10001100;
here bLoc = 1;
now for next iteration,
aLoc will be 3 as next '1' is at 3rd position
and bLoc will be 5 so naturally aLoc
which means '1' comes first in string a.
Hence
if(aLoc<bLoc)
a>b;
Let a = 01, b = 10.
In your program, in the first iteration, the value of a[i]^b[i] will be 1. But a[i] < b[i] and you have not accounted for this case, thus the value of x remains 0.
In the second iteration, again the XOR condition is true, and the condition (a[i] > b[i]) is also true, thus incrementing the value of x to 1.
After the loop, it will print 01 > 10 which is obviously false.
Modified Code:
#include <iostream>
int main() {
std::string a, b;
std::cin >> a >> b;
int la = a.length(), lb = b.length();
int x = 0;
// -1 if both are equal
// 0 if a > b
// 1 if b > a
int flag = -1;
// if you only want to check for equal length strings
if (la == lb)
{
for (int i = 0; i < la; i++)
{
if (a[i]^b[i] == 1)
{
if(a[i] > b[i])
flag = 0;
else
flag = 1;
break;
}
}
if (flag == 0)
std::cout << a << " > " << b << std::endl;
if (flag == 1)
std::cout << a << " < " << b << std::endl;
if (flag == -1)
std::cout << a << " = " << b << std::endl;
}
}
Related
i want to asking this problem.
this output is the expected output
*
*#
*#%
*#%*
*#%*#
*#%*#%
and this is my solution
#include <iostream>
using namespace std;
int main(){
int a,b,n;
cout << "Input the row";
cin >> n;
for (a = 1; a <= n; a++){
for(b = 1; b <= a; b++){
if (b == 1 || b == 1 + 3){
cout << "*";
}
if (b ==2 || b == 2 + 3){
cout << "#";
}
if (b ==3 || b == 3 + 3){
cout << "%";
}
}
cout << endl;
}
}
this solution is only work if the n = 6. what should i do if i want this work in every row when user input the row to the n
thank you in advance.
Here, I tried using the modulo "%" on your if's
#include <iostream>
using namespace std;
int main(){
int a,b,n;
cout << "Input the row";
cin >> n;
for (a = 1; a <= n; a++){
for(b = 1; b <= a; b++){
// After every first digits will cout #
if (b % 3 == 2){
cout << "#";
}
// The first after the third digit will cout *
if (b % 3 == 1){
cout << "*";
}
// The third digit after the second digit will cout %
if (b % 3 == 0){
cout << "%";
}
}
cout << endl;
}
}
To make your solution work for any value of n, you can use the modulo operator % to check whether a given value of b is the first, second, or third element of each row.
Here is one way you could modify your code to do this:
#include <iostream>
using namespace std;
int main() {
int a, b, n;
cout << "Input the row: ";
cin >> n;
for (a = 1; a <= n; a++) {
for (b = 1; b <= a; b++) {
// Use the modulo operator to check whether b is the first, second, or third element of each row
if (b % 3 == 1) {
cout << "*";
} else {
if (b % 3 == 2) {
cout << "#";
} else {
cout << "%";
}
}
}
cout << endl;
}
return 0;
}
With this change, the code will output the correct pattern for any value of n.
Just adding a nice optimisation (note: C++ loops naturally go up from 0 to not including n, i.e. for(int i = 0; i < n; ++i) – this is especially relevant if you are indexing arrays which have a first index of 0 and last of n - 1, while n already is invalid!).
While you do use b % 3 to decide which character and you indeed can use this by chaining if(){} else if(){} else{} (where a switch() { case: case: default: } actually would have been preferrable) you can have a much more compact version as follows (and even more efficient as it avoids conditional branching):
for(int b = 0; b < a; ++b)
{
std::cout << "*#%"[b % 3];
}
The C-string literal "*#%" actually represents an array of char with length four (including the terminating null character) – and you can index it just like any other array you have explicitly defined (like int n[SOME_LIMIT]; n[7] = 1210;)...
For Example, I have number 1 + 6 + 7 + 12 + 13 + 18+.....+ n (n is the input from users which represent the number of elements) the index of this number starts from 1 by this it means that if the index is an odd number (1,3,5...) I want to increment the element at that index by 5 and if the index is an even number I want to increment the element at that index by 1 until I reach the of n number of elements. What I want is to sum all those numbers.
Sorry, It may hard to understand because of my poor English So let me write some of my C code here:
using namespace std;
int i, n, result = 0;
cout << "Input number to sum: ";
cin >> n;
// Finding result
for (i = 0; i <= n; i++){
if (i % 2 == 0) {
result +=i;
} else {
result += i * 5;
}
}
// Make last number have equal sign "1+6+7+12 = 36"
for (i = 0; i <= n; i++){
if (i == n) {
cout << i..?? << "=";
} else {
cout << i..?? << "+";
}
}
// Print result out
cout << result;
return 0;
}
Combine the computation with the output (I usually preach the opposite, but in this case it actually simplifies matters).
for (int i = 0; i <= n; i++)
{
int value = i % 2 == 0 ? i + 1 : i + 5;
cout << (i > 0 ? " + " : "") << value;
result += value;
}
cout << " = " << result;
I agree with the molbdnilo that combining calculations and output in this case, simplify the code.
I don't agree with the algorithm, though, given OP's description.
In the following the calculations are repeated to output the result
#include <iostream>
int main()
{
int n;
std::cout << "Input number to sum: ";
std::cin >> n;
auto update = [] (int i) { return i % 2 == 0 ? 1 : 5; };
int result = 0;
int value = 0;
for (int i = 0; i < n; i++)
{
value += update(i);
result += value;
}
std::cout << '\n';
for (int i = 0, value = 0; i < n; i++)
{
value += update(i);
std::cout << (i > 0 ? " + " : "") << value;
}
std::cout << " = " << result;
}
Testable here.
I agree with molbdnilo's answer. However the algorithm some changes.
The index starts from 1 , so value check for i in for loop should be
for (int i = 0; i < n; i++)
while updating the values, increment should be done on value and not on i.
Here is my solution:
using namespace std;
int main()
{
int i, n, result, value = 0;
cout << "Input number to sum: ";
cin >> n;
for (i = 0; i < n; i++)
{
value = i % 2 == 0 ? value + 1 : value + 5;
cout << (i > 0 ? " + " : "") << value;
result += value;
}
cout << " = " << result;
return 0;
}
Testable here
Problem
I am trying to write a program that can output all of a numbers prime factors. I started by making a function to check whether a factor is prime or not:
bool checkPrime() {
for (x = 1; x <= i; ++x) {
if (x % i != 0) {
return 1;
}
else {
return 0;
}
}
Main
int main() {
cout << "Enter any positive number: " << endl;
cin >> n;
cout << "Prime Factors of " << n << " are: " << endl;
for (i = 1; i <= n; ++i) {
if (n % i == 0) {
for (x = 1; x <= i; ++x) {
cout << i << " ";
}
}
cout << "\n";
system("pause");
}
Question
How can I implement my "checkPrime" function to check whether or not I run:
cout << i << " ";
I reckon the problem is to print the boolean return value of checkPrime() function as true or false. I'm not going in to the correctness of checkPrime() function in this answer. But for your purpose use something like the following.
std::cout << std::boolalpha << checkPrime() << std::noboolalpha << std::endl;
Refer: https://en.cppreference.com/w/cpp/io/manip/boolalpha
I didn't look into you checkPrime() function, but ideally it should accept n as an argument.
Change checkPrime to accept an input.
Fix the the implementation. The current implementation is not correct.
Add a call to the function in main and output the number based on the return value of the function.
bool checkPrime(int i)
{
// 1 and 2 are primes
if ( i < 2 )
{
return true;
}
if ( i % 2 == 0 )
{
return false;
}
// Check with only odd numbers.
// Division by even numbers is not necessary.
// Even numbers greater than 2 are not prime numbers.
// Also, you don't need to check for division by numbers greater than sqrt(i)
for (x = 3; x*x <= i; x +=2 )
{
if ( i % x == 0)
{
return false;
}
}
return true;
}
In main:
for (i = 1; i <= n; ++i)
{
if (n % i == 0 )
{
if ( checkPrime(i) )
{
cout << i << " ";
}
}
}
You can combine the two if statements into one if statement.
for (i = 1; i <= n; ++i)
{
if (n % i == 0 && checkPrime(i) )
{
cout << i << " ";
}
}
I'm working on a simple game (rock, paper, scissors) and I got this problem when I try to populate a vector with using elements of another vector as conditions. The code maybe is more easy to understand:
#include "stdafx.h"
#include "../../Library/std_lib_facilities.h"
// With the fibonacci series I can generate a secret sequence of number
int fib(int n){
if (1 == n || 2 == n) {
return 1;
}
else {
return fib(n - 1) + fib(n - 2);
}
}
// It shows the list of element in a given vector
void showVector(vector<int>myVector, string nameVector) {
cout << "\n\n";
cout << nameVector << " Debug: | ";
for (int i = 1; i < 10; i++) {
cout << myVector[i] << " | ";
}
cout << "\n\n";
}
// String variant
void showVector(vector<string>myVector, string nameVector) {
cout << "\n\n";
cout << nameVector << " Debug: | ";
for (int i = 1; i < 10; i++) {
cout << myVector[i] << " | ";
}
cout << "\n\n";
}
// Generate a sequence of number in a vector
vector<int> generateCode(int input) {
vector<int>myVector;
for (int i = 1; i <= 10; i++) {
myVector.push_back(fib(i + input) % 3);
}
return myVector;
}
int main()
{
// Secret sequence of moves, based on the value (0, 1 or 2) i will show Rock, Paper or Scissor
vector<int>fibSeries;
vector<string>movSeries;
// Initialization and settings
int input = 0;
cout << "Digit an integer to start: ";
while (cin >> input) {
// Check the number to make sure is a valid one (i will implement a check later) and generate the secret code
fibSeries = generateCode(input);
// For each 0 i'll put Rock in the vector, same for 1 ( in this case paper ) and 2 ( scissor )
for (int i = 0; i <= fibSeries.size(); i++) {
if (fibSeries[i] == 0){
movSeries.push_back("Rock");
}
else if (fibSeries[i] == 1) {
movSeries.push_back("Paper");
}
else if (fibSeries[i] == 2) {
movSeries.push_back("Scissor");
}
else {
movSeries.push_back("Rock");
}
}
// Shows the vector graphically, for debug.
showVector(fibSeries, "fibisSeries");
showVector(movSeries, "movSeries");
// So for a combination of 1 - 2 - 0 - 1
// The result should be: Paper - Scissor - Rock - Paper
}
return 0;
}
After i execute the code, i get an (Abort). I don't understand, I'm new to C++ so please forgive me if is a stupid error. And most of the code is complex becouse I have rules to follow, so for example if I didn't study something i can't use it here. I just want to know why the code don't want me to use the for with the vector!
for (int i = 0; i <= fibSeries.size(); i++)
As #Yola mentions, you iterate one element more than you have:
if you have the vector std::vector<char> v = {'a', 'b', 'c'};, the elements can be accessed as:
v[0] (-> 'a')
v[1] (-> 'b')
v[2] (-> 'c')
As a rule, your max index will be length - 1.
for (int i = 0; i <= fibSeries.size(); i++)
iterates from 0 to less then or equal to size(); that is, 0, 1, 2, 3 (4 elements, in a 3 elements vector).
Correct code should be:
for (int i = 0; i < fibSeries.size(); i++)
^^^
So as has already been stated, your problem is that you should always use < size because indexing is 0-based <= size will read off the end of allocated space.
But a couple comments if I may, c++11 introduced a new style of range based for-loops which will save you from having to write the condition and iteration expressions at all:
map<int, string> movSeries = { { 0, "Rock"s }, { 1, "Paper"s }, { 2, "Scissors"s } };
vector<int> fibSeries(10);
auto input = 0;
while(cin >> input) {
for(auto& i : fibSeries) {
i = fib(input++) % 3;
}
cout << "\n\nDebug | ";
copy(cbegin(fibSeries), cend(fibSeries), ostream_iterator<int>(cout, " | "));
cout << "\n\n\n\nDebug | ";
for(const auto i : fibSeries) {
cout << movSeries[i] << " | ";
}
cout << endl << endl;
}
I am working on a program that emulates conways game of life, and it works perfectly with the preset dimensions. However, once i try to use the dynamic dimensions as seen in option e, i start having problems. The main problem is in the "life" function which iterates throughout the array and decides if it should bring to life a cell. I have been debugging for a while and it i enter the dimensions as 50*40, it iterates until 61, 1. This should technically work but it just breaks everytime. Keep in mind that I add 12 to each dimension to account for the buffer zone I put around the edges. Technically it should work then right? If you have any suggestions I would really appreciate it!
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <new> // i havent used this one yet
#include <cmath>
using namespace std;
// REMEMBER: The outside of the array is 6 more than what we show so that nothing interferes
//also that it goes y,x and that x is going to be bigger so that we get a rectange
//we use the copy function to copy an array from eachother, either the current one to the temp one or
//vise versa. This is so that we can alter the cells one step at a time without affecting everything else.
void copy(int **array1, int **array2, int o, int p)
{
for(int j = 0; j < o; j++)
{
for(int i = 0; i < p; i++)
array2[j][i] = array1[j][i];
}
} // the second array sent is assigned the first array sent!
//this array will initialize our arrays so that we can use them later
int** init(int n, int m)
{
int **array;
array = new int*[m]; // x
array = new int*[n]; // y
for (int q=0; q < n; q++)
{
array[q] = new int[n];
for (int w=0; w < m; w++)
{
array[w] = new int[m];
}
}
return array;
}
void populate(int o, int p, int** board){ // THIS FUNCTION HASN'T BEEN USED YET
for(int i=0; i < p; i++)
{
for(int j=0; j < o; j++) // It was in a in-class demo but i dont think i need it
{
board[i][j] = pow(i, j);
}
}
}
//The life function looks at the pieces around the cell and figures out what happens next.
// Probably the most important in the entire program, feast your eyes!
void life(int **array, int o, int p)
{
//Copies the main array to a temp array so changes can be made without affecting anyone else
int **temp;
temp = init(o, p);
copy(array, temp, o, p);
for(int j = 1; j < o; j++)
{
for(int i = 1; i < p; i++)
{
// checks all 8 cells surrounding it
int count = 0;
cout << " j is " << j << " and i is " << i << endl;
// cout << array[j][i]; // DEBUGGING
count =
array[j-1][i] + array[j-1][i-1] +
array[j][i-1] + array[j+1][i-1] +
array[j+1][i] + array[j+1][i+1] +
array[j][i+1] + array[j-1][i+1];
//cell dies.
if(count < 2 || count > 3)
{
temp[j][i] = 0;
}
//nothing happens.
if(count == 2)
{
temp[j][i] = array[j][i];
}
//now the cell will be born, or if it already is alive then it stays that way.
if(count == 3)
{
temp[j][i] = 1;
}
}
}
//Copies the temp array back to the main array.
copy(temp, array, o, p);
}
//This function prints the 40 x 50 part of the array, a 1 means that there will be a cell there,
//otherwise it will just be an empty space.
void print(int **array, int o, int p)
{
// WE ONLY CHECK WHAT WE SEE, WHICH IS 6 LESS THAN THE ARRAY!!!
for(int j = 6; (j < (o-6)); j++)
{
for(int i = 6; (i < (p-6)); i++)
{
if(array[j][i] == 1 )
cout << '*';
else
cout << '.';
}
cout << endl;
}
}
//I read somewhere it would be a good idea to make sure to end the program early if it somehow
//became stable by itself early. so this compares the old array with the new one to check if they
//are the same. This commonly occurs if a glider runs off the screen for example.
bool compare(int **array1, int **array2,int o,int p)
{
int counter = 0;
for(int j = 0; j < o; j++)
{
for(int i = 0; i < p; i++)
{
if(array1[j][i]==array2[j][i])
counter++;
}
}
if(counter == o*p)
return true;
else
return false;
}
int main()
{
int o= 52, p=62;
int **firstgen;
int **next;
int **backup;
// 40 + 12, 50 + 12
int x, y;
char starty;
char again;
char cont;
bool comparison;
//Here is where we initialize our arrays
firstgen = init(o,p);
next = init(o,p);
backup = init(o,p);
cout << endl << "Welcome to John Conway's Game of Life." << endl;
//This loop is for if we are still simulating, don't get confused!
do
{
//this loop checks for inputs.
do
{
menu: //this is a goto we use for if we change dimensions
x = 0, y = 0;
//now we get the menu
cout << endl << "--- Choose an option Below ---" << endl;
cout << "(a) Glider" << endl;
cout << "(b) Gosper Gilder gun" << endl;
cout << "(c) R Pentomino Pattern" << endl;
cout << "(d) Oscillator" << endl;
cout << "(e) Change the dimensions (it defaults to (50*40)" << endl;
cin >> starty;
}while(starty != 'a' && starty != 'b' && starty != 'c' && starty != 'd' && starty != 'e');
int i = 0;
//we need to assign firstgen in this area
//choose a glider position
if (starty == 'a'){
x= 0, y= 0;
cout << " X dimension: ";
cin >> x;
cout << " Y dimension: ";
cin >> y;
if (x < 0 || x > p || y < 0 || y > o){
cout << endl << "you entered invalid dimensions" << endl;
goto menu;
}
x = x+6; //we add 6 because there are six spots to the left that aren't shown we need to account for
y = y+6;
//creates the glider
firstgen[y][x] = 1;
firstgen[y][x+1] = 1;
firstgen[y][x+2] = 1;
firstgen[y-1][x] = 1;
firstgen[y-2][x+1] = 1;
}
else if (starty == 'b'){
x= 0, y= 0;
cout << "Your dimensions are based on the farthest left point" << endl;
cout << " X dimension: ";
cin >> x;
cout << " Y dimension: ";
cin >> y;
if (x < 0 || x > p || y < 0 || y > o){
cout << endl << "you entered invalid dimensions" << endl;
goto menu;
}
//this is because we have the buffer zone of 6
x = x+6;
y = y+6;
//Gosper gun
//box on left
firstgen[y][x] = 1;
firstgen[y][x+1] = 1;
firstgen[y+1][x] = 1;
firstgen[y+1][x+1] = 1;
//left circle starting in top of the left curve (flat part)
firstgen[y][x+10] = 1;
firstgen[y-1][x+11] = 1;
firstgen[y-2][x+12] = 1;
firstgen[y-2][x+13] = 1;
firstgen[y+1][x+10] = 1;
firstgen[y+2][x+10] = 1;
firstgen[y+3][x+11] = 1;
firstgen[y+4][x+12] = 1;
firstgen[y+4][x+13] = 1;
//dot in middle
firstgen[y+1][x+14] = 1;
//arrow thing on the right
firstgen[y-1][x+15] = 1;
firstgen[y][x+16] = 1;
firstgen[y+1][x+16] = 1;
firstgen[y+1][x+17] = 1;
firstgen[y+2][x+16] = 1;
firstgen[y+3][x+15] = 1;
//boomerang bit on the far right section
firstgen[y][x+20] = 1;
firstgen[y][x+21] = 1;
firstgen[y-1][x+20] = 1;
firstgen[y-1][x+21] = 1;
firstgen[y-2][x+20] = 1;
firstgen[y-2][x+21] = 1;
firstgen[y-3][x+22] = 1;
firstgen[y-3][x+24] = 1;
firstgen[y-4][x+24] = 1;
firstgen[y+1][x+22] = 1;
firstgen[y+1][x+24] = 1;
firstgen[y+2][x+24] = 1;
//tiny box on farthest right, almost done!
firstgen[y-1][x+34] = 1;
firstgen[y-1][x+35] = 1;
firstgen[y-2][x+34] = 1;
firstgen[y-2][x+35] = 1;
}
else if (starty == 'c')
{
x= 0, y= 0;
cout << "Your dimensions are based on the farthest left point" << endl;
cout << " X dimension: ";
cin >> x;
cout << " Y dimension: ";
cin >> y;
if (x < 0 || x > p || y < 0 || y > o){
cout << endl << "you entered invalid dimensions" << endl;
goto menu;
}
x = x+6;
y = y+6;
//creates R Pentamino pattern
firstgen[y][x] = 1;
firstgen[y][x+1] = 1;
firstgen[y+1][x+1] = 1;
firstgen[y-1][x+1] = 1;
firstgen[y-1][x+2] = 1;
}
// creates the simple oscillator
else if (starty == 'd')
{
x= 0, y= 0;
cout << "Your dimensions are based on the top of the oscillator" << endl;
cout << " X dimension: ";
cin >> x;
cout << " Y dimension: ";
cin >> y;
if (x < 0 || x > p || y < 0 || y > o){
cout << endl << "you entered invalid dimensions" << endl;
goto menu;
}
x = x+6;
y = y+6;
firstgen[y][x] = 1;
firstgen[y+1][x] = 1;
firstgen[y+2][x] = 1;
}
// allows you to choose your dimensions
else if (starty == 'e')
{
o= 0, p= 0;
x= 0, y= 0;
cout << "choose the height and width of your field, between 0 and 100" << endl;
cout << " X dimension: ";
cin >> x;
cout << " Y dimension: ";
cin >> y;
if (x < 0 || x > 100 || y < 0 || y > 100){
cout << endl << "Please keep dimensions between 0 and 100" << endl;
goto menu;
}
// the problem is that it is adding my x dimension and my placement choice together and then
// starts to run the program, which threadbreaks. I need to find out why these two values are
// adding together and fix it
x = x+12;
y = y+12; // plus twelve so that we have 6 around all sides
p = x;
o = y;
firstgen = init(o,p);
next = init(o,p);
backup = init(o,p);
// is this part below necessary?
//firstgen[o][p];
// next[o][p];
// backup[o][p];
// idk
// cout << "y value is: " << o << " and the x value is " << p << endl; // debugging
goto menu;
}
//Loop that does the simulation.
do
{
//Prints the generation. If i == 0, the firstgen array is copied to the
//next array, and is printed before any functions act upon it.
cout << endl << "Generation " << i << ":" << endl << endl;
//Initializes the arrays by copying the firstgen array to the next array.
if(i == 0)
copy(firstgen, next, o, p);
//this stuff below happens in every cycle
cout << "the x/p value is" << p << "and the y/o value is " << o << endl;
copy(next, backup, o, p);
print(next, o, p);
life(next, o, p);
i++;
//Pauses the system .2 seconds so that it doesn't flash past you super fast and you
// can't appreciate its beauty
system("sleep .2");
//Checks whether the generation is a multiple of 100 to ask
//the user if they want to continue
if(i % 100 == 1 && i != 1)
{
cout << endl;
//Loop to check for proper inputs.
do
{
cout << "Continue? (y or n): ";
cin >> cont;
}while(cont != 'y' && cont != 'n');
if(cont == 'n')
break;
}
//Compares the current generation with a backup generation.
//The idea is that if it is the same with the backup generation then
//something boring is going on or smething went wrong. It will end if that
//is the case.
comparison = compare(next, backup, o, p);
if(comparison == false)
// system("clear");
//cout << string( 10, '\n' );
if(comparison == true)
cout << endl;
}while(comparison == false);
//Loop to check if we want to keep going.
do
{
cout << "Run another Simulation? (y or n): ";
cin >> again;
}
while(again != 'y' && again != 'n');
//this is where we clean out all our firstgen values
//i used to have this at the top but didn't really need it
for(int y = 0; y < o; y++)
{
for(int x = 0; x < p; x++)
{
firstgen[y][x] = 0;
}
}
}
while(again == 'y');
return 0;
}
I figured it out!
The thing to take away from this is to make sure that your initiation function creates the array with the same size as the one you will be accessing. I was trying to get values from array[52][1] which didn't exist because in my init function i only had the for loop running while n < o, which means it didn't create the 52nd row. what a relief!