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 )
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.
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?
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!!!
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.
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..
double bonus = calcBonus(bonus, sale);
//bonus is undeclared in main(). it's only declared as an argument in calcBonus()
//sales is also 0.0, from previous function
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.
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 usingnamespace std; at the top of everything. Does it use more memory/cpu or something?
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.
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.
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
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:
// 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.