I'd just like to go on record as saying your professor is an asshole for teaching you recursion before you even learn the basics of the language.
I'd just like to go on record as saying your professor is an asshole for teaching you recursion before you even learn the basics of the language.
Right-o thanks![]()
As I (may have) mentioned earlier, this is one of the problems I had with the assistance that the teacher was giving. I can see why someone might say this (they didn't each method overloading yet), but it really feels like a poor job being done by the teacher. (S)He has not done a very good job introducing basic programming concepts, which has made a fairly trivial problem difficult to understand. Recursion itself is not a difficult concept (a function that calls itself), but without an understanding of the stack, return types, and the steps in which the application executes, I'm not sure the students are gaining the information that they need to in order to prepare themselves for future tasks.
Tajin: You probably shouldn't have copy-pasted that code. It has several syntax errors (recursive not always returning a value), incorrect prime logic (as was said a few posts back, one is not a prime), and your removal of the isPrime function makes it so a function that doesn't exist is being called.
You are correct good sir, fixing the mess.
Edit: Done, it is still a mess but eh, you posted the answer anyway on page 1 <.<
I'm totally at a loss as to why you'd be instructed to learn recursion prior to learning a simple concept such as boolean anything. I mean, recursion is a pretty simple concept when you see it in action (properly), but seriously, case operations are so common that learning what boolean means and how to implement it should be something you learn early on... unless they don't touch on if-then-else stuff until later in the class, which I suspect is the case here.
I agree with this <.< When I first saw the topic, I thought either: 1. the OP has no fucking clue what he's doing and is taking wrong class/wrong major, 2. the professor is shit, 3. OP isn't going to class/paying any attention in class.
There's nothing wrong with teaching recursion early, but teaching it before the super basic stuff mentioned in the above post that the OP couldn't fully grasp is just, weird/wrong.
And I don't get all the people bitching about booleans -_- Maybe it's because I didn't do C++, but regular C, which required doing retarded shit if you wanted to use the words true and false instead of 1/0, but it just seems silly. As long as you understand that 0=false and 1=true, I don't see the problem with either method. I mean, if the language supports booleans, using true/false is obviously better, but I still don't get all of the bitching. lol
edit: 6666 <_>
I would find it difficult to believe that the instructor didn't go over the if/then construct before giving this assignment.
If I were teaching this class, the lesson plan would be something like:
Primitive datatypes (char, int, long, short, byte, float, double, bool), specifically what these are (size in bits, signed and unsigned range, scenarios in which each should be used).
Variable Declarations
Control Structures (if/then/else, for, while, do while, switch, break, continue) with assignments taliored to using each structure.
Methods (return types, naming conventions, and parameters)
With these topics, an instructor has the ability to expand simple applications with new information. Recursion, for example, could be introduced after calculating prime numbers in a for loop. This would be a good way to not only how recursion changes the application structure, but also a way to introduce the stack, error cases, validating input, and operator overloading.
Aristio: If you actually want to gain an understanding of programming, I would try to make sure you have a grasp on those topics. As I've said before, I don't know the scope of the class, but knowing datatypes and control structures will be important.
Honestly, though, if the students are having trouble with recursion, I can't imagine what is going to happen when (s)he teaches them references/pointers/memory management.
Recursion is tightly related to mathematics and it makes perfect sense if you're teaching programming from a mathematical point of view tightly related to functional programming.
You don't need to know every primitive type in order to understand logic and functions. In fact I would argue it's an unimportant, trivial thing. He obviously understands the concept if he's using if statements appropriately.
I can tell you I've learned:
- char
- int
- float
- double
- bool
- if/else
- for
- while
- do while
- signed/unsigned
I'm guessing variable declarations are "int x = 9" and naming conventions are what you went over on the first page. I'm working on a new assignment right now, and it has to deal with loops and bools. After everyone explaining it to me, the assignment is pretty simple. Stuck on one point, but I'm sure I'll figure it out.
I didn't learn recursion until the end of my second java class.
So, can anyone tell me what I'm doing wrong?
Spoiler: show
Of course, homework help. I'm having trouble nesting the if statements properly in the class. Would I put the if statements before or after the return of each if statement?
Your problem is in main, not the ifs.
Also, the "&& mygrades <x0"s aren't needed. If they weren't true, you wouldn't be checking the if in the first place.
Everything in main works, when I compile and run the program, it always gives me F no matter the % grade. 160/1.6=100. Still says F though.
Nope. It doesn't. Try ignoring the input and hard coding a value for mygrades, and see what happens. This is an easy way of debugging simple problems like this. If hard coding a value makes it work, then you are feading the function the wrong value. If it doesn't, then the function is wrong.
No, you are sending garbage data in the mygrades variable. Either hard coding mygrades, or using a cout at the top of getOverallLetterGrade would have made that very obvious, even if you didn't know why.
I'm going to bed now, see if you can figure it out from there.
You're not assigning the mygrades variable anywhere in your program, like hey said, you're sending garbage to the method.
Also, don't mix operations between ints and floats/doubles when there's division involved; cast everything appropriate type. I don't remember if all compilers handle 150/1.6 properly, but the opposite order (i.e. 3.6/2) will definitely give you a wrong answer thanks to implicit int conversions.