Getting error “Run-Time Check Failure #2 - Stack around the variable 'midtermgrade' was corrupted.”The Definitive C++ Book Guide and ListRun-Time Check Failure #2 - Stack around the variable 'ap' was corruptedRun-Time Check Failure #2 - Stack around the variable 'my2DArray' was corruptedRun-Time Check Failure #2 - Stack around the variable 'gpa' was corruptedRun-Time Check Failure #2 - Stack around the variable 'foo' was corruptedRun-Time Check Failure #2 - Stack around the variable 'normalIndex' was corruptedRun-Time Check Failure #2 - Stack around the variable 'l1' was corruptedERROR: run-time check failure #2 - stack around the variable was corruptedRun-time check: stack around variable was corruptedRun-Time Check Failure #2 - Stack around the variable 'k' was corruptedRun-Time Check Failure #2 - Stack around the variable “regObj” was corrupted
How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?
How to compactly explain secondary and tertiary characters without resorting to stereotypes?
What is an equivalently powerful replacement spell for Yuan-Ti's Suggestion spell?
Processor speed limited at 0.4 Ghz
What is the fastest integer factorization to break RSA?
What is required to make GPS signals available indoors?
Can a virus destroy the BIOS of a modern computer?
How badly should I try to prevent a user from XSSing themselves?
Mathematica command that allows it to read my intentions
Do Iron Man suits sport waste management systems?
Can someone clarify Hamming's notion of important problems in relation to modern academia?
Why were 5.25" floppy drives cheaper than 8"?
How exploitable/balanced is this homebrew spell: Spell Permanency?
Could neural networks be considered metaheuristics?
What does the same-ish mean?
Finitely generated matrix groups whose eigenvalues are all algebraic
Does marriage to a non-Numenorean disqualify a candidate for the crown of Gondor?
What is the opposite of "eschatology"?
What is the most common color to indicate the input-field is disabled?
Is it a bad idea to plug the other end of ESD strap to wall ground?
Should I tell management that I intend to leave due to bad software development practices?
How to show a landlord what we have in savings?
Different meanings of こわい
My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?
Getting error “Run-Time Check Failure #2 - Stack around the variable 'midtermgrade' was corrupted.”
The Definitive C++ Book Guide and ListRun-Time Check Failure #2 - Stack around the variable 'ap' was corruptedRun-Time Check Failure #2 - Stack around the variable 'my2DArray' was corruptedRun-Time Check Failure #2 - Stack around the variable 'gpa' was corruptedRun-Time Check Failure #2 - Stack around the variable 'foo' was corruptedRun-Time Check Failure #2 - Stack around the variable 'normalIndex' was corruptedRun-Time Check Failure #2 - Stack around the variable 'l1' was corruptedERROR: run-time check failure #2 - stack around the variable was corruptedRun-time check: stack around variable was corruptedRun-Time Check Failure #2 - Stack around the variable 'k' was corruptedRun-Time Check Failure #2 - Stack around the variable “regObj” was corrupted
Currently trying to run the program I've written and getting the error "Run-Time Check Failure #2 - Stack around the variable 'midtermgrade' was corrupted."
I have no idea what to do to fix it, very new to programming and got thrown into a C++ course that I certainly did not have the background for.
Using Visual Studio 2017.
Code is supplied below.
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
double mean(int v[], int size);
// PRE: size of array > 0
// POST: return average of values in array
double stddev(int v[], int size, double m);
// PRE: size of array > 0, 0 <= m <= 100
// POST: return standard deviation of values in array with mean m
char letter(int score, double m, double s);
// PRE: 0 <= score, m, s <= 100
// POST: return letter grade for score with mean m and standard deviation s
string code(string id, string lastname, string firstname);
// PRE: id is seven digit identification
// POST: return code of first letter of last name, first letter of first name, last two digits of id
int main()
ifstream fin;
ofstream fout;
fin.open("grades.txt");
fout.open("grades.txt");
const int CAPACITY = 25; // capacity of the array
string codes[CAPACITY]; // array of id codes
int midterms[CAPACITY]; // array of midterm grades
int finals[CAPACITY]; // array of final grades
string id; // 6-digit id code
string lastname;
string firstname; // Student's year of school
int midterm;
int final;
string idcode;
double finalmean; // Average grade on the final
double finalstddev; // Standard deviation among final grades
double midtermmean; // Average grade on the midterm
double midtermstddev; // Standarn deviation among midterm grades
char finalgrade[CAPACITY]; // An array of the letter grades for the final
char midtermgrade[CAPACITY]; // An array of the letter grades for the midterm
int ct = 0;
while (ct < CAPACITY && fin >> id >> lastname >> firstname >> midterm >> final)
midterms[ct] = midterm;
finals[ct] = final;
idcode = code(id, lastname, firstname);
codes[ct] = idcode;
++ct;
finalmean = mean(finals, CAPACITY);
midtermmean = mean(midterms, CAPACITY);
finalstddev = stddev(finals, CAPACITY, finalmean);
midtermstddev = stddev(midterms, CAPACITY, midtermmean);
for (int i = 0; i <= CAPACITY; i++)
finalgrade[i - 1] = letter(finals[i - 1], finalmean, finalstddev);
midtermgrade[i - 1] = letter(midterms[i - 1], midtermmean, midtermstddev);
fout << "Grade Calculations" << endl << "By ----" << endl;
for (int i = 1; i <= CAPACITY; i++)
fout << setprecision(1);
fout << setw(15) << codes[i - 1] << setw(15) << midterms[i - 1]
<< midtermgrade[i - 1] << setw(15) << finals[i - 1]
<< finalgrade[i - 1] << endl;
fout << endl << endl;
fout << "The class mean for the midterm exam was a " << midtermmean << endl;
fout << "The standard deviation amongst the midterm exams was +/- " << midtermstddev << endl;
fout << endl << endl;
fout << "The class mean for the final exam was a " << finalmean << endl;
fout << "The standard deviation amongst the final exams was +/- " << finalstddev << endl;
fin.close();
fout.close();
return 0;
string code(string id, string lastname, string firstname)
// PRE: id is seven digit identification
// POST: return code of first letter of last name, first letter of first name, last two digits of id
char firstletterfirst = firstname[0];
char firstletterlast = lastname[0];
char fifthdigitid = id[4];
char sixthdigitid = id[5];
string idcode = firstletterfirst, firstletterlast, fifthdigitid, sixthdigitid ;
return idcode;
double mean(int v[], int size)
// PRE: size of array > 0
// POST: return average of values in array
int sum = 0;
for (int i = 1; i <= size; i++)
sum = sum + v[i - 1];
double mean = sum / size;
return mean;
double stddev(int v[], int size, double m)
double sumofsquares = 0;
double spread[25];
double var;
double stddev;
for (int i = 1; i < size; i++)
spread[i - 1] = (v[i - 1] - m)*(v[i - 1] - m);
sumofsquares = sumofsquares + spread[i - 1];
var = sumofsquares / 25;
stddev = sqrt(var);
return stddev;
char letter(int score, double m, double s)
// PRE: 0 <= score, m, s <= 100
// POST: return letter grade for score with mean m and standard deviation s
char grade;
if (score < (m - (1.5 * s)))
grade = 'E';
else if (score >= (m - (1.5 * s)) && score < (m - (0.5*s)))
grade = 'D';
else if (score >= (m - s) && score < m)
grade = 'C';
else if (score >= (m+(0.5*s)) && score < (m + 1.5*s))
grade = 'B';
else
grade = 'A';
return grade;
c++ visual-studio-2017
|
show 1 more comment
Currently trying to run the program I've written and getting the error "Run-Time Check Failure #2 - Stack around the variable 'midtermgrade' was corrupted."
I have no idea what to do to fix it, very new to programming and got thrown into a C++ course that I certainly did not have the background for.
Using Visual Studio 2017.
Code is supplied below.
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
double mean(int v[], int size);
// PRE: size of array > 0
// POST: return average of values in array
double stddev(int v[], int size, double m);
// PRE: size of array > 0, 0 <= m <= 100
// POST: return standard deviation of values in array with mean m
char letter(int score, double m, double s);
// PRE: 0 <= score, m, s <= 100
// POST: return letter grade for score with mean m and standard deviation s
string code(string id, string lastname, string firstname);
// PRE: id is seven digit identification
// POST: return code of first letter of last name, first letter of first name, last two digits of id
int main()
ifstream fin;
ofstream fout;
fin.open("grades.txt");
fout.open("grades.txt");
const int CAPACITY = 25; // capacity of the array
string codes[CAPACITY]; // array of id codes
int midterms[CAPACITY]; // array of midterm grades
int finals[CAPACITY]; // array of final grades
string id; // 6-digit id code
string lastname;
string firstname; // Student's year of school
int midterm;
int final;
string idcode;
double finalmean; // Average grade on the final
double finalstddev; // Standard deviation among final grades
double midtermmean; // Average grade on the midterm
double midtermstddev; // Standarn deviation among midterm grades
char finalgrade[CAPACITY]; // An array of the letter grades for the final
char midtermgrade[CAPACITY]; // An array of the letter grades for the midterm
int ct = 0;
while (ct < CAPACITY && fin >> id >> lastname >> firstname >> midterm >> final)
midterms[ct] = midterm;
finals[ct] = final;
idcode = code(id, lastname, firstname);
codes[ct] = idcode;
++ct;
finalmean = mean(finals, CAPACITY);
midtermmean = mean(midterms, CAPACITY);
finalstddev = stddev(finals, CAPACITY, finalmean);
midtermstddev = stddev(midterms, CAPACITY, midtermmean);
for (int i = 0; i <= CAPACITY; i++)
finalgrade[i - 1] = letter(finals[i - 1], finalmean, finalstddev);
midtermgrade[i - 1] = letter(midterms[i - 1], midtermmean, midtermstddev);
fout << "Grade Calculations" << endl << "By ----" << endl;
for (int i = 1; i <= CAPACITY; i++)
fout << setprecision(1);
fout << setw(15) << codes[i - 1] << setw(15) << midterms[i - 1]
<< midtermgrade[i - 1] << setw(15) << finals[i - 1]
<< finalgrade[i - 1] << endl;
fout << endl << endl;
fout << "The class mean for the midterm exam was a " << midtermmean << endl;
fout << "The standard deviation amongst the midterm exams was +/- " << midtermstddev << endl;
fout << endl << endl;
fout << "The class mean for the final exam was a " << finalmean << endl;
fout << "The standard deviation amongst the final exams was +/- " << finalstddev << endl;
fin.close();
fout.close();
return 0;
string code(string id, string lastname, string firstname)
// PRE: id is seven digit identification
// POST: return code of first letter of last name, first letter of first name, last two digits of id
char firstletterfirst = firstname[0];
char firstletterlast = lastname[0];
char fifthdigitid = id[4];
char sixthdigitid = id[5];
string idcode = firstletterfirst, firstletterlast, fifthdigitid, sixthdigitid ;
return idcode;
double mean(int v[], int size)
// PRE: size of array > 0
// POST: return average of values in array
int sum = 0;
for (int i = 1; i <= size; i++)
sum = sum + v[i - 1];
double mean = sum / size;
return mean;
double stddev(int v[], int size, double m)
double sumofsquares = 0;
double spread[25];
double var;
double stddev;
for (int i = 1; i < size; i++)
spread[i - 1] = (v[i - 1] - m)*(v[i - 1] - m);
sumofsquares = sumofsquares + spread[i - 1];
var = sumofsquares / 25;
stddev = sqrt(var);
return stddev;
char letter(int score, double m, double s)
// PRE: 0 <= score, m, s <= 100
// POST: return letter grade for score with mean m and standard deviation s
char grade;
if (score < (m - (1.5 * s)))
grade = 'E';
else if (score >= (m - (1.5 * s)) && score < (m - (0.5*s)))
grade = 'D';
else if (score >= (m - s) && score < m)
grade = 'C';
else if (score >= (m+(0.5*s)) && score < (m + 1.5*s))
grade = 'B';
else
grade = 'A';
return grade;
c++ visual-studio-2017
3
The debugger is trying to tell you that you likely have stepped out of bounds in one of your arrays.
– drescherjm
Mar 21 at 20:36
6
for (int i = 1; i <= CAPACITY; i++)
all of these are wrong. Valid indices are 0 .. CAPACITY -1. Should befor (int i = 0; i < CAPACITY; i++)
– drescherjm
Mar 21 at 20:38
2
That initial loop where you read input, it looks like you should spend more time learning classes and structures. As well as the standard C++ containers (most specificallystd::vector
). I recommend you get a couple of good books to read along your course.
– Some programmer dude
Mar 21 at 20:40
In the IDE, one way to find things like this is to step through your code and look for the point where a stack variable becomes corrupted. Or set a watch on the variable.
– Dave S
Mar 21 at 20:40
1
Ditch all those C-style arrays. Usestd::array
orstd::vector
instead.
– Jesper Juhl
Mar 21 at 20:46
|
show 1 more comment
Currently trying to run the program I've written and getting the error "Run-Time Check Failure #2 - Stack around the variable 'midtermgrade' was corrupted."
I have no idea what to do to fix it, very new to programming and got thrown into a C++ course that I certainly did not have the background for.
Using Visual Studio 2017.
Code is supplied below.
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
double mean(int v[], int size);
// PRE: size of array > 0
// POST: return average of values in array
double stddev(int v[], int size, double m);
// PRE: size of array > 0, 0 <= m <= 100
// POST: return standard deviation of values in array with mean m
char letter(int score, double m, double s);
// PRE: 0 <= score, m, s <= 100
// POST: return letter grade for score with mean m and standard deviation s
string code(string id, string lastname, string firstname);
// PRE: id is seven digit identification
// POST: return code of first letter of last name, first letter of first name, last two digits of id
int main()
ifstream fin;
ofstream fout;
fin.open("grades.txt");
fout.open("grades.txt");
const int CAPACITY = 25; // capacity of the array
string codes[CAPACITY]; // array of id codes
int midterms[CAPACITY]; // array of midterm grades
int finals[CAPACITY]; // array of final grades
string id; // 6-digit id code
string lastname;
string firstname; // Student's year of school
int midterm;
int final;
string idcode;
double finalmean; // Average grade on the final
double finalstddev; // Standard deviation among final grades
double midtermmean; // Average grade on the midterm
double midtermstddev; // Standarn deviation among midterm grades
char finalgrade[CAPACITY]; // An array of the letter grades for the final
char midtermgrade[CAPACITY]; // An array of the letter grades for the midterm
int ct = 0;
while (ct < CAPACITY && fin >> id >> lastname >> firstname >> midterm >> final)
midterms[ct] = midterm;
finals[ct] = final;
idcode = code(id, lastname, firstname);
codes[ct] = idcode;
++ct;
finalmean = mean(finals, CAPACITY);
midtermmean = mean(midterms, CAPACITY);
finalstddev = stddev(finals, CAPACITY, finalmean);
midtermstddev = stddev(midterms, CAPACITY, midtermmean);
for (int i = 0; i <= CAPACITY; i++)
finalgrade[i - 1] = letter(finals[i - 1], finalmean, finalstddev);
midtermgrade[i - 1] = letter(midterms[i - 1], midtermmean, midtermstddev);
fout << "Grade Calculations" << endl << "By ----" << endl;
for (int i = 1; i <= CAPACITY; i++)
fout << setprecision(1);
fout << setw(15) << codes[i - 1] << setw(15) << midterms[i - 1]
<< midtermgrade[i - 1] << setw(15) << finals[i - 1]
<< finalgrade[i - 1] << endl;
fout << endl << endl;
fout << "The class mean for the midterm exam was a " << midtermmean << endl;
fout << "The standard deviation amongst the midterm exams was +/- " << midtermstddev << endl;
fout << endl << endl;
fout << "The class mean for the final exam was a " << finalmean << endl;
fout << "The standard deviation amongst the final exams was +/- " << finalstddev << endl;
fin.close();
fout.close();
return 0;
string code(string id, string lastname, string firstname)
// PRE: id is seven digit identification
// POST: return code of first letter of last name, first letter of first name, last two digits of id
char firstletterfirst = firstname[0];
char firstletterlast = lastname[0];
char fifthdigitid = id[4];
char sixthdigitid = id[5];
string idcode = firstletterfirst, firstletterlast, fifthdigitid, sixthdigitid ;
return idcode;
double mean(int v[], int size)
// PRE: size of array > 0
// POST: return average of values in array
int sum = 0;
for (int i = 1; i <= size; i++)
sum = sum + v[i - 1];
double mean = sum / size;
return mean;
double stddev(int v[], int size, double m)
double sumofsquares = 0;
double spread[25];
double var;
double stddev;
for (int i = 1; i < size; i++)
spread[i - 1] = (v[i - 1] - m)*(v[i - 1] - m);
sumofsquares = sumofsquares + spread[i - 1];
var = sumofsquares / 25;
stddev = sqrt(var);
return stddev;
char letter(int score, double m, double s)
// PRE: 0 <= score, m, s <= 100
// POST: return letter grade for score with mean m and standard deviation s
char grade;
if (score < (m - (1.5 * s)))
grade = 'E';
else if (score >= (m - (1.5 * s)) && score < (m - (0.5*s)))
grade = 'D';
else if (score >= (m - s) && score < m)
grade = 'C';
else if (score >= (m+(0.5*s)) && score < (m + 1.5*s))
grade = 'B';
else
grade = 'A';
return grade;
c++ visual-studio-2017
Currently trying to run the program I've written and getting the error "Run-Time Check Failure #2 - Stack around the variable 'midtermgrade' was corrupted."
I have no idea what to do to fix it, very new to programming and got thrown into a C++ course that I certainly did not have the background for.
Using Visual Studio 2017.
Code is supplied below.
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
double mean(int v[], int size);
// PRE: size of array > 0
// POST: return average of values in array
double stddev(int v[], int size, double m);
// PRE: size of array > 0, 0 <= m <= 100
// POST: return standard deviation of values in array with mean m
char letter(int score, double m, double s);
// PRE: 0 <= score, m, s <= 100
// POST: return letter grade for score with mean m and standard deviation s
string code(string id, string lastname, string firstname);
// PRE: id is seven digit identification
// POST: return code of first letter of last name, first letter of first name, last two digits of id
int main()
ifstream fin;
ofstream fout;
fin.open("grades.txt");
fout.open("grades.txt");
const int CAPACITY = 25; // capacity of the array
string codes[CAPACITY]; // array of id codes
int midterms[CAPACITY]; // array of midterm grades
int finals[CAPACITY]; // array of final grades
string id; // 6-digit id code
string lastname;
string firstname; // Student's year of school
int midterm;
int final;
string idcode;
double finalmean; // Average grade on the final
double finalstddev; // Standard deviation among final grades
double midtermmean; // Average grade on the midterm
double midtermstddev; // Standarn deviation among midterm grades
char finalgrade[CAPACITY]; // An array of the letter grades for the final
char midtermgrade[CAPACITY]; // An array of the letter grades for the midterm
int ct = 0;
while (ct < CAPACITY && fin >> id >> lastname >> firstname >> midterm >> final)
midterms[ct] = midterm;
finals[ct] = final;
idcode = code(id, lastname, firstname);
codes[ct] = idcode;
++ct;
finalmean = mean(finals, CAPACITY);
midtermmean = mean(midterms, CAPACITY);
finalstddev = stddev(finals, CAPACITY, finalmean);
midtermstddev = stddev(midterms, CAPACITY, midtermmean);
for (int i = 0; i <= CAPACITY; i++)
finalgrade[i - 1] = letter(finals[i - 1], finalmean, finalstddev);
midtermgrade[i - 1] = letter(midterms[i - 1], midtermmean, midtermstddev);
fout << "Grade Calculations" << endl << "By ----" << endl;
for (int i = 1; i <= CAPACITY; i++)
fout << setprecision(1);
fout << setw(15) << codes[i - 1] << setw(15) << midterms[i - 1]
<< midtermgrade[i - 1] << setw(15) << finals[i - 1]
<< finalgrade[i - 1] << endl;
fout << endl << endl;
fout << "The class mean for the midterm exam was a " << midtermmean << endl;
fout << "The standard deviation amongst the midterm exams was +/- " << midtermstddev << endl;
fout << endl << endl;
fout << "The class mean for the final exam was a " << finalmean << endl;
fout << "The standard deviation amongst the final exams was +/- " << finalstddev << endl;
fin.close();
fout.close();
return 0;
string code(string id, string lastname, string firstname)
// PRE: id is seven digit identification
// POST: return code of first letter of last name, first letter of first name, last two digits of id
char firstletterfirst = firstname[0];
char firstletterlast = lastname[0];
char fifthdigitid = id[4];
char sixthdigitid = id[5];
string idcode = firstletterfirst, firstletterlast, fifthdigitid, sixthdigitid ;
return idcode;
double mean(int v[], int size)
// PRE: size of array > 0
// POST: return average of values in array
int sum = 0;
for (int i = 1; i <= size; i++)
sum = sum + v[i - 1];
double mean = sum / size;
return mean;
double stddev(int v[], int size, double m)
double sumofsquares = 0;
double spread[25];
double var;
double stddev;
for (int i = 1; i < size; i++)
spread[i - 1] = (v[i - 1] - m)*(v[i - 1] - m);
sumofsquares = sumofsquares + spread[i - 1];
var = sumofsquares / 25;
stddev = sqrt(var);
return stddev;
char letter(int score, double m, double s)
// PRE: 0 <= score, m, s <= 100
// POST: return letter grade for score with mean m and standard deviation s
char grade;
if (score < (m - (1.5 * s)))
grade = 'E';
else if (score >= (m - (1.5 * s)) && score < (m - (0.5*s)))
grade = 'D';
else if (score >= (m - s) && score < m)
grade = 'C';
else if (score >= (m+(0.5*s)) && score < (m + 1.5*s))
grade = 'B';
else
grade = 'A';
return grade;
c++ visual-studio-2017
c++ visual-studio-2017
edited Mar 21 at 20:38
1201ProgramAlarm
17.9k52740
17.9k52740
asked Mar 21 at 20:36
stin1516stin1516
1
1
3
The debugger is trying to tell you that you likely have stepped out of bounds in one of your arrays.
– drescherjm
Mar 21 at 20:36
6
for (int i = 1; i <= CAPACITY; i++)
all of these are wrong. Valid indices are 0 .. CAPACITY -1. Should befor (int i = 0; i < CAPACITY; i++)
– drescherjm
Mar 21 at 20:38
2
That initial loop where you read input, it looks like you should spend more time learning classes and structures. As well as the standard C++ containers (most specificallystd::vector
). I recommend you get a couple of good books to read along your course.
– Some programmer dude
Mar 21 at 20:40
In the IDE, one way to find things like this is to step through your code and look for the point where a stack variable becomes corrupted. Or set a watch on the variable.
– Dave S
Mar 21 at 20:40
1
Ditch all those C-style arrays. Usestd::array
orstd::vector
instead.
– Jesper Juhl
Mar 21 at 20:46
|
show 1 more comment
3
The debugger is trying to tell you that you likely have stepped out of bounds in one of your arrays.
– drescherjm
Mar 21 at 20:36
6
for (int i = 1; i <= CAPACITY; i++)
all of these are wrong. Valid indices are 0 .. CAPACITY -1. Should befor (int i = 0; i < CAPACITY; i++)
– drescherjm
Mar 21 at 20:38
2
That initial loop where you read input, it looks like you should spend more time learning classes and structures. As well as the standard C++ containers (most specificallystd::vector
). I recommend you get a couple of good books to read along your course.
– Some programmer dude
Mar 21 at 20:40
In the IDE, one way to find things like this is to step through your code and look for the point where a stack variable becomes corrupted. Or set a watch on the variable.
– Dave S
Mar 21 at 20:40
1
Ditch all those C-style arrays. Usestd::array
orstd::vector
instead.
– Jesper Juhl
Mar 21 at 20:46
3
3
The debugger is trying to tell you that you likely have stepped out of bounds in one of your arrays.
– drescherjm
Mar 21 at 20:36
The debugger is trying to tell you that you likely have stepped out of bounds in one of your arrays.
– drescherjm
Mar 21 at 20:36
6
6
for (int i = 1; i <= CAPACITY; i++)
all of these are wrong. Valid indices are 0 .. CAPACITY -1. Should be for (int i = 0; i < CAPACITY; i++)
– drescherjm
Mar 21 at 20:38
for (int i = 1; i <= CAPACITY; i++)
all of these are wrong. Valid indices are 0 .. CAPACITY -1. Should be for (int i = 0; i < CAPACITY; i++)
– drescherjm
Mar 21 at 20:38
2
2
That initial loop where you read input, it looks like you should spend more time learning classes and structures. As well as the standard C++ containers (most specifically
std::vector
). I recommend you get a couple of good books to read along your course.– Some programmer dude
Mar 21 at 20:40
That initial loop where you read input, it looks like you should spend more time learning classes and structures. As well as the standard C++ containers (most specifically
std::vector
). I recommend you get a couple of good books to read along your course.– Some programmer dude
Mar 21 at 20:40
In the IDE, one way to find things like this is to step through your code and look for the point where a stack variable becomes corrupted. Or set a watch on the variable.
– Dave S
Mar 21 at 20:40
In the IDE, one way to find things like this is to step through your code and look for the point where a stack variable becomes corrupted. Or set a watch on the variable.
– Dave S
Mar 21 at 20:40
1
1
Ditch all those C-style arrays. Use
std::array
or std::vector
instead.– Jesper Juhl
Mar 21 at 20:46
Ditch all those C-style arrays. Use
std::array
or std::vector
instead.– Jesper Juhl
Mar 21 at 20:46
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288856%2fgetting-error-run-time-check-failure-2-stack-around-the-variable-midtermgra%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288856%2fgetting-error-run-time-check-failure-2-stack-around-the-variable-midtermgra%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
The debugger is trying to tell you that you likely have stepped out of bounds in one of your arrays.
– drescherjm
Mar 21 at 20:36
6
for (int i = 1; i <= CAPACITY; i++)
all of these are wrong. Valid indices are 0 .. CAPACITY -1. Should befor (int i = 0; i < CAPACITY; i++)
– drescherjm
Mar 21 at 20:38
2
That initial loop where you read input, it looks like you should spend more time learning classes and structures. As well as the standard C++ containers (most specifically
std::vector
). I recommend you get a couple of good books to read along your course.– Some programmer dude
Mar 21 at 20:40
In the IDE, one way to find things like this is to step through your code and look for the point where a stack variable becomes corrupted. Or set a watch on the variable.
– Dave S
Mar 21 at 20:40
1
Ditch all those C-style arrays. Use
std::array
orstd::vector
instead.– Jesper Juhl
Mar 21 at 20:46