#homework help

55 messages · Page 1 of 1 (latest)

frozen sable
#

Hello guys, this is my first semester of computer programming and the basics of C are a little confusing to me. So far i've learned basic commands such as the ones in the screenshot. any help would be appreciated

fading daggerBOT
#

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.

lilac elk
#

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"

frozen sable
#

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

lilac elk
#

Ok so what are you actually struggling with?

frozen sable
#

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

lilac elk
#

It would have to be a float or double, yes. That sounds fine otherwise

frozen sable
#

is it written just float or is there such thing as a constant ? since i dont want the value im giving it to change

lilac elk
#

const float is fine

frozen sable
#

how can I multiply the value of a float with the number the user inputs

#

would i also have to have a "total" variable ?

neon field
#

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.

frozen sable
unkempt aurora
frozen sable
#

!howtoask

#

how can I make an integer value applied by the user multiply by a literal float value

unkempt aurora
#

What

#

By doing it.

frozen sable
#

Geez thanks, it’s my third week of this

fading daggerBOT
#

@frozen sable Has your question been resolved? If so, type !solved :)

unkempt aurora
#

But you have to rephrase your question because i don't know what you meant

frozen sable
#

I need to get a whole value number multiply with a decimal number but I don’t know how to

bronze remnant
#

You want to multiply an integer, supplied by the user, with a float?

frozen sable
#

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

bronze remnant
#

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.

frozen sable
#

my numbers are still coming out like the screenshot above

#

i found i was missing a %d but its still gives me large numbers

bronze remnant
#

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.

frozen sable
bronze remnant
#

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.

frozen sable
#

thank you so much, may i ask what are pointers ?

bronze remnant
#

Every variable is stored somewhere in memory. When you use the & operator, you are telling the function to retrieve that address.

frozen sable
#

the & operator is the pointer ?

bronze remnant
#

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.

frozen sable
#

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

bronze remnant
#

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.

frozen sable
#

I see, thank you friend for the insight

#

!solved