#homework help
55 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
What is line 6 supposed to do?
Currently, when that newline is ignored, that variable declaration reads as int const int tax = 8.25, where you have a duplicated "int"
I didnt continue on it but line 6 is supposed to be for the entree items ?
since they have to be in variables to be able to get a total cost of x (amount) of units being ordered
the assignment has examples of what the program is supposed to look like
Ok so what are you actually struggling with?
i have many questions but as of right now, would I have to give each entree a const int for each variable to hold the price value ?
or would it have to be a float since it has a decimal point
It would have to be a float or double, yes. That sounds fine otherwise
is it written just float or is there such thing as a constant ? since i dont want the value im giving it to change
const float is fine
how can I multiply the value of a float with the number the user inputs
would i also have to have a "total" variable ?
You might want to use a double for that constant.
You could make the input itself a float or. . .
Use a double instead. You should be able to convert an int to a double like this:
int a = 3;
double b;
double tax = 8.25;
b = (double) a * tax;
Try it and let me know.
I don’t think I’m allowed to use doubles in this assignment since it has not been covered. We’ve only covered integer variables, floats and constants.
The cast is unnecessary. The int will be promoted to double implicitly. Both multiplying with a double and assigning to it do it.
!howtoask
how can I make an integer value applied by the user multiply by a literal float value
Geez thanks, it’s my third week of this
@frozen sable Has your question been resolved? If so, type !solved :)
You're welcome. Over time your brain will adapt to the overwhelming pressure of the C language existing until you become numb
But you have to rephrase your question because i don't know what you meant
I need to get a whole value number multiply with a decimal number but I don’t know how to
You want to multiply an integer, supplied by the user, with a float?
this is what i have so far, ive put the integers at 0 because i want the user to input the value is this correct ?
in line 40 im trying to multiply the integer and float but it does not let me
The first thing i would do is change the total variable to a double
if you do 1 * 6.50, and it tries to cram that result into an integer, the result will turn into 6 instead of 6.50
Also, you are printing out the total before you have calculated the total.
my numbers are still coming out like the screenshot above
i found i was missing a %d but its still gives me large numbers
Those warnings are because those variables are not integers. When you put %d into printf you are telling the function to interpret the values as integers — they are floats. To tell printf you are inputting floats you can use %f (i think) or %.3f or to limit the amount of decimals.
Ah, sorry. Printf does not want pointers to those variables. You can pass them in without the & operator., after which you will need to change the format specifier (%d) to the correct format specifier for each respective variable.
Every variable is stored somewhere in memory. When you use the & operator, you are telling the function to retrieve that address.
the & operator is the pointer ?
The & operator is the “address of” operator, It gets the address of a variable. A pointer is sorta similar. The address POINTS TO the variable, sorta thing — i’m not sure what the perfect way to explain it is.
I think I understand what you're trying to say, the & has the the address and the pointer well it points.. lol
same same but different
also my other question is why the use of a double and not a float ?
whats the difference
You could use a float, the reason i recommend a double is because a double is more precise and when working with money it’s better to be more precise.