Visual Studio 2015 IDE breaking for no reason [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Whenever I run this code, my IDE is breaking (no specific error just this Windows messages that says Programm doesn't work anymore).
Could you check if it is due to my code?
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i; int array1[10], array2[10];
for (i = 0; 1 < 10; i++) {
array1[i] = i;
array2[i] = i;
}
array2[9] = 30;
for (i = 0; i < 10; i++) {
if (array1[i] == array2[i]) {
continue;
}
else {
printf("Die Arrays unterscheiden sich an Position %d\n", i);
break;
}
}
return 0;
}

Yes, I assume it is your code.
1 < 10 is always true. So for (i = 0; 1 < 10; i++) {...} runs forever.
I imagine what you meant to do was more like...
for (i = 0; i < 10; i++) {...}

Related

C++, error: ā€˜iā€™ was not declared in this scope in a for loop [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm trying to do a code that pop_back()-s numbers[i] into either one of these vectors: oddnumbers and evennumbers
but unfortunately I got ' 'i' was not declared in this scope'
the code is following:
#include <iostream>
#include <vector>
int main() {
std::vector<int> numbers = {2,4,3,6,1,9};
std::vector<int> evennumbers;
std::vector<int> oddnumbers;
for (i = 0; i < numbers[6]; i++) {
if (numbers[i]%2 == 0) {
evennumbers.pop_back(numbers[i]);
}
else if (numbers[i]%2 != 0) {
oddnumbers.pop_back(numbers[i]);
}
}
}
As the compiler says, there is no declaration of i.
Replace
for (i = 0; i < numbers[6]; i++) {
by
for (int i = 0; i < numbers[6]; i++) {

SelectionSorting in c++ (Error : EXC_BAD_ACCESS) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I just recently learned to do selection sorting an array. I am also using X-Code on a mac.
I thought I did everything correctly, but I seem to keep getting this error message on the if statement :
Thread 1: EXC_BAD_ACCESS(code=1, address=0x7fff5fc00000).
What am I doing wrong?
using namespace std;
void selectionSorting(int array[], int n)
{
for(int i = 0; i < n-1; n++)
{
int min = i;
for(int j = i + 1; j < n; j++)
{
if(array[j] < array[min]) //Thread 1: EXC_BAD_ACCESS(code=1, address=0x7fff5fc00000)
min = j;
}
int temp = array[i];
array[i] = array[min];
array[min] = temp;
}
}
int main()
{
int n = 10;
int array[]= {10,9,8,7,6,5,4,3,2,1};
selectionSorting(array, n);
for(int x=0; x < n; x++)
{
cout << array[x] << " ";
}
return 0;
}
You have a logical error at for(int i = 0; i < n-1; n++). It should be for(int i = 0; i < n-1; i++) (iterate through the elements of the array).
Also EXC_BAD_ACCESS suggests that your are trying to access a piece of memory that is no longer accessible or it doesn't go well with the intended use.
See that this occurs at if(array[j] < array[min]), which is obvious because j is going beyond the array length as you do n++.
As suggested in the comments try using a debugger.

My program skips the if statement [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm writing a program that would make a power of a matrix.
as you see, I'm trying to ask at the for (int n...) loop if n==0,
but when I'm debugging - I see that the program just skips the condition and doesn't even enter it. I mean it doesn't even "ask" the question if n==0...
What is the problem?
void Matrix::pow(int power, Matrix & result)
{
for (int i = 0; i < power-1; i++)
{
for (int j = 0; j < rows; j++)
{
for (int k = 0; k < cols; k++)
{
for (int n = 0; n < cols; n++)
{
if (n==0)
{
(&result)->_array[i][j] == 0; //Reset result's array.
}
(&result)->_array[i][j] += this->_array[i][n] * this->_array[n][j];
}
}
}
}
}
This is a boolean expression, not an assignment.
(&result)->_array[i][j] == 0; //Reset result's array.

Generating a random out of 2 dice roll [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I fixed the typos that I had in my code, and now it runs perfect
int rollDice(int diceRoll[], int numberRolling) // Random dice rolls
{
int values = 0;
for (int i = 0; i < numberRolling; i++)
{
diceRoll[i] = 1 + rand() % 6;
}
for (int i = 0; i < numberRolling; i++)
{
values = values + diceRoll[i];
}
return values;
}
You have a typo in your first for
for (int i = 0; i < numberRolling, i++)
Should be
for (int i = 0; i < numberRolling; i++)

Using arrays to find a maximum [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I take in an array I go through all it's elements, if any member of the array is greater than j, than it makes that element the new j. For some reason I keep getting back that the maximum is 4. What's going on?
##include <iostream>
using namespace std;
int MAXIM(int arg[],int sz){
int j = 0;
for(int i = 0; i < sz; i++){
if(arg[i] > j){
j = i;
}
}
return j;
}
int main(){
int coolarr[5] = {5,17,45,7,34};
int maxxy = MAXIM(coolarr, 5);
cout << maxxy << endl;
}
j = i; this line is wrong; it should be j = arg[i];.