Ok but in the cose I must use "void" or it is right?
If the total (vat included) is 80 the vat results 16 and the vat-free price results 64 that isn't right.....
Yeah you need to make the function return void. You can also make double &t a const (constdouble &t for stressing that it won't be changed by the function.
I understand about const double &t , but I don't understand well about I must use void in the code, can you rewrite all the code right please?
void is simply a keyword in the language that means 'no type' or 'nothing' depending on context.
void foo()
{
cout <<"boring function";
}
this function does not return any values that it computed, because it had none. The type of the function is void, because that is how c++ works: you must put a return type on a function in c++, and if you don't have one, that type is the void keyword.
compare to
double f(double x);
{
return x/3.14;
}
this one returns a double, a value that you can use and of a type you can do things with.
method 1:
void returnstwo( double in1, double in2, double &out1, double&out2)
{
blah blah;
out1 = result1;
out2 = result2;
}
..
main
returnstwo(11.3,2.718, r1,r2);
//here r1 and r2 are your two answers.
method 2, create your own return type or use standard pair or other container for it. (I made my own because one day you will need to see how to do this, pair is fine for 2 values)
struct s
{
double res1;
double res2;
}
s returns2(double in1, double in2);
{
s ans;
ans.res1 = result1;
ans.res2 = result2;
return ans;
}
etc. so the point is that you can use any container (vector, array/pointer, pair/point) or your own user defined type (class or struct) to return a group of values from a function. Use a container if you can, and make your own type only if you need that type anyway OR there is no better way to do it (say you had a string, a double, and a myclass to return instead of just a couple of doubles... that would be tough to do without a custom wrapper).
method 1 is preferred here because the problem is very simple, but method 2 is what you will see more and more as you get into more advanced coding problems.
Can you write all code please?
Really many thanks!
yes, I can write the code. Can you? Give it a try. Me writing the code won't help you pass the class, it just puts you further behind than you already are.
start small. I will give you working code, this time, since the pseudocode seems to have confused you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void getpiande(double &pi, double &e)
{
pi = 3.14;
e = 2.718;
}
int main()
{
double PI = 0.0;
double E = 0.0;
getpiande(PI,E);
cout << PI << endl;
cout << E << endl;
}
that demonstrates what you asked. Now use that idea in your code.
just make it a habit when dealing with doubles to make doubles. divide by 120.0. You don't need that here, because t helps you out, but one day you will be glad you are doing this as a habit.
Codeblocks (CB) is not a compiler. It uses a compiler. Its installer probably installed a compiler too.
When you say "compile" in CB, the CB runs the compiler with some options (program code's filename, etc).
There must be in CB a way to select/add/change those options.
The most likely compiler under CB is (some version) GCC. GCC has many options.
The warning message shows that if one has option -Wreturn-type, then one gets this warning.
If one has option -Wall, then one has -Wreturn-type too.
Options -Wall -Wextra is quite good.
GCC has also option -std. It requires a value. For example: -std=c++11. The possible values depend on the version of GCC. The std option determines which version of C++ is supported.