Stats: 3,191,954 members, 7,946,142 topics. Date: Wednesday, 11 September 2024 at 01:13 PM |
Nairaland Forum / Science/Technology / Programming / Help On This Code (1293 Views)
Please,Help Explain This Code In C / Java Code Pls Modify This Code Help / Java Programmers ,I Need Help Fixing This Code. (2) (3) (4)
Help On This Code by Justiceotuya(m): 11:35pm On Jan 10, 2017 |
Hello programmers, I am a noob in programming and was told that to learn more, I need to do some project and so i started this GPA calculator that eventually prints your GPS in both 5unit and it 4 unit equivalent. The problem is I created an array to hold the grade point from A-F and another array to hold the letter grade from 0-5, but after I was done it performed well until I noticed it crashes when I try to calculate for more than 6 course, I have tried what I can do but still can't detect the bug. I need help before I run mad (lol) cc dhtml and others
|
Re: Help On This Code by DangotePikin: 11:25am On Jan 12, 2017 |
Is it an ArrayOutOfBound exception? |
Re: Help On This Code by peterincredible: 12:23pm On Jan 12, 2017 |
op the fault is 4rm the ( gradepoint and lettergrade which have a pridefined index of 6) unlike the (score,creditunit and qualitypoint which their index is determined by the variable(numofcode) so to me to correct the bug make the number of index in the gradepoint and lettergrade array be determined by the numofcourse variable i mean in ure code change the int gradepoint[6],lettergrade[6] to intgradepoint[numofcode] and int lettergrade[numofcode] i think with this ure problem is solved tank u very much |
Re: Help On This Code by peterincredible: 12:29pm On Jan 12, 2017 |
and i forgot if u remember the for loop use numofcourse variable to check the amount of loop it will execute but the the gradepoint and lettergrade array has a fixed index of 6 so when you now make numofcourse variable 7 or higher number it will make gradepoint and lettergrade throw an exception tanks |
Re: Help On This Code by elfico(m): 1:56pm On Jan 12, 2017 |
@OP, first of all, what Compiler or IDE are you using? Because as I understand, what you doing currently is illegal in C++ except of course you are using C99 (a version of C that could be used as an extension in C++) You cannot declare an array without a constant value at compile time. That is, int numOfCourse; int scores[numOfCourse]; //illegal. You can solve this by using a dynamic array i.e, by using new and delete operators a. int numOfCourse; cin >> numOfCourse int *scores = new int[numOfCourse]; //all other codes here delete[] scores //very important b. int numOfCourse = 5; // declare the size of the vector vector<int> scores(size, 0); // create a vector to hold "size" ints all initialized to zero scores[0] = 1234; // assign values like a c++ array |
Re: Help On This Code by Justiceotuya(m): 7:32pm On Jan 14, 2017 |
elfico:Thanks, I am using DEV c++ and it actually compiles. Thanks for the Tip.the problem is that letter grade and grade point must be predefined to 6 to hold 0-5 and A-F |
Re: Help On This Code by asalimpo(m): 1:42am On Jan 15, 2017 |
use codeblocks please. Dev-C++ is bad. |
(1) (Reply)
Android Developer Needed / I Can Design Your Website ** Already Made Ponzi Site Available For Sale Too. / Best Cloud Mining Bitcoin Script | Available With Demo Here
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 31 |