|
| j3tt (53) | |||
I'm getting 56 errors on this. I'm still learning the basics of functions and how exactly to set them up...
| |||
| Bazzy (4118) | |
| On line 29 and 36 you aren't specifying the return type On line 32 you should use >> instead of << In calcBonus you are assigning to a variable called 'bonus' which wasn't declared in that scope ( you can just return sales * .1 without using any variable ) | |
| jsmith (3802) | |
| Line 29 and 36: You didn't specify the return type of the function. Line 32: << is the extraction operator (used with cout, not cin). Line 38: bonus is undeclared in the function. | |
| j3tt (53) | |||
I'm getting an error on line 20: cannot pass function with zero arguments. But when I enter double sales, sales, or just double it gives me back more errors. what am I missing?
| |||
| Bazzy (4118) | |
| Remove the parameter bonus on line 35, remove line 37 as it will overwrite the argument passed | |
| j3tt (53) | |||
still wont work. i don't get it.
| |||
| Bazzy (4118) | |
| What's wrong with it? | |
| j3tt (53) | |
| the compiler is giving me a warning when compiling it, then when it executes the program it gives me an error pop up saying debug error: sales is being used without being initialized. I initialized sales into the getSales function and still giving me this error pop up. frustration!!! | |
| guestgulkan (1299) | |
double sales = getSales(sales); //here You may be assigning the return value of the getSales function to the sales variable, but you are passing a copy of it's uninitialised value to the function to begin with - that is what the compiler is complaining about. | |
Last edited on | |
| Bazzy (4118) | |
| I didn't see that, anyway the use of parameters in your program isn't correct. You should read the tutorial: http://www.cplusplus.com/doc/tutorial/functions/ | |
| j3tt (53) | |||
i read the functions I tutorial. am i not declaring something right? im getting 1 error and its giving me this looong error message i'm not going to bother with posting..
| |||
| ljrobison (57) | |||||
I think your problem is with this line:
Im pretty sure you cant cin a function, but Im not to sure on that. At least we have never done it in my class. However, you can change all this:
to just: using namespace std; | |||||
| bluezor (237) | |||||
| @j3tt, There are some mistakes in your code.
And as ljrobison said, you can't cin >> that particular function.@ljrobison, It's actually better to use using std::what_i_need over the whole namespace. If you include the whole namespace, it's like using all that extra code in your file, which is unnecessary and a waste of space. | |||||
Last edited on | |||||
| ljrobison (57) | |
Thanks bluezor. I didn't really know that, my teacher just kinda said, you'll use everything in the std library alot so just put using namespace std; at the top of everything. Does it use more memory/cpu or something? | |
| gcampton (782) | ||
actually that's untrue it makes no difference either way. BUT YOU SHOULDN'T use namespace std; because you don't know what is in it yet, so using std::cin etc, you won't run into problems. at least until you learn everything inside standard namespace and what traps to avoid. | ||
Last edited on | ||
| bluezor (237) | |
| My bad D: I just found a page which explains it pretty well - http://www.cplusplus.com/forum/beginner/15930/ You should mainly read the responses by Helios. | |
| gcampton (782) | |||
| yea realistically it shouldn't be used at all, but code looks extremely ugly and bulky without it. at least in my eyes, heres an example:
and that's only the header file :S doesn't include all the file handling, cout, cin, cerr, exit etc etc etc you use throughout code. | |||
Last edited on | |||
| bluezor (237) | |
It doesn't look that messy for me xD. For that case though, you can see that you're just using std::string, so an easy using std::string; will do the job :D | |
| gcampton (782) | |
| yea pretty pisspoor example if you ask me LOL, anyway verging on trolling now. quick help the OP!!! cin >> getSales(); you can't do this because getSales(); <---- takes no parameters, so reading something in via keyboard you can't pass it to getSales();, you perhaps could if you had say: cin >> variable; getSale(variable); with the getSale method looking like: double getSale(int number) { double sales = 0.0; return sales; // but then you probably want to do something with the variable 'number' perhaps assign it to sales? } you really need to go scratch your code, as you methods variables don't really make sense. or fix it so it does, ask yourself what does the code need to do, then write it down in english. for example, last night I completed an assignment in 2-3hours, that we were given 5 weeks to accomplish(bar a few stackdump errors)... and the reason is because of pseudocode: task was to read in a file containing any number of lines. store the lines in an array with no duplicate lines, and output to another file. I have been sitting playing with command line args for about 1 week, when i decided to give up on it and write the rest of my code, which only took me a couple hours. Because i sat down before writing anything and wrote pseudocode with pad and pen. If I hadn't done this my code would probably be alot more bulky, and not systematic. perhaps even came accross multiple errors. And probably taken 10 times longer the pseudocode was as follows; ::input:: -handle exceptions ......(try / catch) - create input stream obj ...... (ifstream) - check if file opened ...... (conditional if statement) - while not end of file and array is not full ...... ((! input.eof())&&(array[size-1].empty())) - grab next line from file ...... (getline) - traverse array and check if line exists ...... (for (array)) if line==array[i] boolean = true; - else if it doesn't store the line in the array ::done for that method:: - sort array ...... (sort ( array, arraSize); <---- solved this syntax with a post, thanks baz :D ::output:: - handle excpetions ...... (try/catch ) - create output stream obj ...... (ofstream ) - store array in file ...... (for i=0;arraysize;++ ) - don't store null strings ...... (if (! array[i].empty()) output << array[i] << endl; ) done easy as pie. So try to write an english like method to solve your problem, just as I have done... If you can do this then you are a programmer syntax is irrelevant, , if oyu can write pseudocode, then that's all you need to be a programmer the code simply follows, and syntax can always be looked up, logic cannot. | |
Last edited on | |
This topic is archived - New replies not allowed.
