![]() |
|
#1
|
||||
|
||||
help with c++ object assignmentHey, Ive got this small assignment due tomorrow where I have to pass objects to functions. The header file and implementation file for the class works fine. Its the driver thats giving me a headache. I can't figure out why Im getting this error:
Error E2277 C:\UVSC\CNS1250\projects\complexNumbers\main.cpp 37: Lvalue required in function main() Here is the code causing the problem. I'll comment on the line number where the problem is: CPP / C++ / C Code:
I went and researched the cause of this error and found that it's supposed to be due to me trying to put a value into an array that can't go into an array. The thing is, however, that I don't have an array anywhere in my code! Last edited by Mjkramer21 : 10-Apr-2004 at 22:15.
Reason: Please enclose c code in [c] & [/c] for syntax highlighting
|
|
#2
|
||||
|
||||
|
Is complexed supposed to be of type complex? All you have is the word complexed(); by itself in the middle of indentation land. The LValue error usually pops up when you're doing something with a structured data type, such as a class. Also, the return value of addComplex must be exactly the same type as the variable it's being assigned to in order for aggregate assignment to work. The problem appears to be with complexed().
__________________
-Aaron |
|
#3
|
||||
|
||||
problem fixedyea, I found it
I changed it from: CPP / C++ / C Code:
to: CPP / C++ / C Code:
Duh! I still can't come up with the same values my instructor came up with. Would anybody be willing to look at my code for me and cross examine it with the example? Its 3 weeks until the end of the semester and this is the first program I've had a problem with. I think maybe Im just having a bad day. Maybe I should sleep on it. Thanks for your feedback. |
|
#4
|
||||
|
||||
|
You probably just goofed one of the formulas or didn't use parenthesis well enough to clarify operator precedence... I'd be willing to look over your code, though, if you feel that you need help. I wrote the same program using regular structured data-types instead of classes. You can have a look at that if you'd like. The coding is very clear and easy to follow, and the formulas are tested and correct.
__________________
-Aaron |
|
#5
|
||||
|
||||
|
CPP / C++ / C Code:
__________________
-Aaron |
|
#6
|
||||
|
||||
|
Well that would be great if I could use structures. But I can't and I have to have a main as well. You can view the instructions here:
debryro.uvsc.edu. I will attach my files incase your offer to look at my program is still open. Everything up until main is the way its supposed to be. Im just having a problem with the logic in main. I keep working it through in my head but keep coming up with the same thing. The program is adding the real numbers in both sets but not the imaginary for some reason, which doesnt makes sense because the addition of the real and imaginary takes place in the same function, one right after the other. |
|
#7
|
||||
|
||||
|
When you take your input for the first imaginary number, you're accidentally taking the input into imag2 instead of imag1. This is most likely causing your problem.
__________________
-Aaron |
|
#8
|
||||
|
||||
|
I edited the bajesus out of your program. I pretty much just changed all the doubles to ints, because you're probably never going to take a double for a complex number. Also, I added a print function to your class, which it should have already had. Finally, I changed your include and define statements, which all had semi-colons at the end of them... where the heck did you pick that habit up?! You also should use ".h" at the end of all your system headers instead of just the name of the file... you were saying <iostream>, which does actually exist in most compilers, but it's dumb to do that because it's the same as <iostream.h>, and it's better to be in the habit of using ".h" at the end of all of your includes.
__________________
-Aaron |
|
#9
|
||||
|
||||
|
I don't know, thats just what I was told to do. When I got my associates degree at a small tech school they told me to use .h but here at this 4 year college they said I don't have to do that anymore. Like you said most compilers don't care these days.
You obviously know what your doing though. Yea, that program isn't nearly complete yet. I have to clean it up, add comments, and print the results from a funtion. They are strict when it comes to style and all. At this point I was just trying to figure the logic with subtracting and adding the objects. Did you ever figure out why it wasnt adding or subtracting the imaginary numbers instead of just the real numbers? |
|
#10
|
||||
|
||||
|
Well, there was nothing wrong with your functions, if that's what you mean. You simply had used imag2 instead of imag1 while taking user input so that imag1 was never initialized and therefore contained garbage data. I didn't change the way your functions worked. I just changed the data type from double to int, and I added a print function, and I printed a small report in main(). I cleaned up your define and include statements, as well. Also, I didn't mean to say that most compilers don't care if you use the .h or not, because they do care. The thing is that most compilers come with an iostream file that doesn't have a .h at the end of it, so you're allowed to do that. If you try to do something like, #include <stdio>, you'll probably get a file-does-not-exist error.
__________________
-Aaron |
Recent GIDBlog
Observations of Iraq by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pointer values changing unexpectedly | spudtheimpaler | C Programming Language | 11 | 04-Mar-2004 16:37 |
| gxx linker accepts only 7 object files | danielxs66 | C++ Forum | 1 | 12-Dec-2003 09:27 |
| Create Vector To Hold Object? | mukcl | C++ Forum | 3 | 15-Oct-2003 09:03 |
| need help to define a class in C++ | yannoush | C++ Forum | 7 | 09-Sep-2003 00:28 |
| How do I access an object from inside another object? | JdS | MySQL / PHP Forum | 5 | 10-Jun-2003 08:51 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The