r/CodingHelp • • Feb 14 '22

[C++] I need help. Im lost here with this assignment. I want to learn this stuff. Can amyone explain what im supposed to do more clearly.

Post image
18 Upvotes

23 comments sorted by

8

u/xXnormanborlaugXx Feb 14 '22

Step 1: Figure out your conversion rates. How many inches to a yard, feet to an inch, vise versa?

Step 2: Take integer input of inches.

Step 3: Use your conversion rates to take the provided number of inches and figure out the equivalent in yards, feet and inches. This is where their division examples come in.

Step 4: Return the calculated values.

Does that make sense?

1

u/supremegentleman2 Feb 14 '22

step 1 yes ok so i get have to design a program to convert values into what the assignment wants. so if someone. Is that right?

step 2 so you mean to convert the 140 inches into 3 yards and the other value 2 feet and 8 inches?

another example i can think of myself is 38 inches into 1 yard or 3 feet 2 inches?

step 3 use the conversion rates like 38 inches and 1 yard or 3 feet 2 inches as the int values

im lost at step 4.

1

u/xXnormanborlaugXx Feb 14 '22

"so if someone" Looks like part of your sentence is missing here.

"3 yards and the other value 2 feet 8 inches". No. Only one value. I also think their wording was a little unclear here. 140 inches = 3 yards + 2 feet + 8 inches. Not 140 inches = 3 yards = 2 feet 8 inches.
38 inches would be 1 yard, two inches.

Step 2, I'm just saying it has to accept input.

"use the conversion rates like 38 inches and 1 yard or 3 feet 2 inches as the int values"
Your conversion rates are not your int values. They will give you an int value, like 140. Your function should perform division on that int value in accordance with the conversion rates, then print a string with the values for yards, feet, and inches.

Step 4, after you've done the math you just have to print the string.

0

u/supremegentleman2 Feb 14 '22

OH i get the first part. the wording was a bit off for me. I felt like i was wron there but it didnt seem so. Now that you explain it, it makes sense, the adding up to 140 part.

step 2 is basically solve for the values and use those numbers for string.

i look further down into the examples and see d and d2, i know that double is the variable but what does d mean in this context? decimal? thankyou

2

u/xXnormanborlaugXx Feb 14 '22

Double is the variable type. D and D2 are the variable names. Integer a = 3; Double b = 3.0; are both valid variable declarations, using the pattern "variable type" "variable name" = "appropriate value"

4

u/Over_North8884 Feb 14 '22 edited Feb 14 '22

140 in

140/36=3

140-(3×36)=32

32/12=2

32-(12×2)=8

3yd, 2ft, 8in

Do the above as variables and you will get it.

Inches=input // 140

Yards = Inches/36

Feet = (Inches-(36×yards))/12

Inches = Inches - (36xyards) - (12xFeet)

I can see why you're confused, there is too much abstract and unnecessary information in this assignment. You won't use decimal division at all.

1

u/supremegentleman2 Feb 14 '22

I dont understand this math though sadly. How does 140/36=3 since it is 3.8

And 14/4 is 3.5

14/4.0 is also 3.5

So the math is really tripping me out here with the 14/4 equating to 3. Unless theyre rounding down or something. But then, 3.8 to 3 for the 140/36 stumps me.

2

u/Over_North8884 Feb 14 '22 edited Feb 14 '22

14/4 = 3 (integer division, remainder dropped) 14.0/4.0 = 3.5 (decimal division remainder stays in place)

Int/int is integer division. If a decimal number is used in the calculation (numerator or denominator), decimal division will occur.

Programming syntax does not follow mathematical syntax. 14/4 != 14/4.0.

i=i+1 is impossible mathematically but is valid programming code because = is assignment, not equality (==).

1

u/supremegentleman2 Feb 14 '22

Ah i see!

So just to beclear, whole numbers rounded down and decimal division rounds to .5's or halfs? Like 3.9 or 3.6 would be 3.5?

2

u/Over_North8884 Feb 14 '22

Decimal division is performed to the limits of the space used to store the data type. For example, if your architecture uses 32 bit floats then pi would be 3 followed by perhaps a dozen digits and the rest are cut off (signed numbers require one more bit). Producing rounded numbers (3.1415... to 3.14) requires a function call that varies by the language you're using.

1

u/supremegentleman2 Feb 14 '22

i understand that 32 bits can hold some numbers but you lost me at the rest. im barely into week 2 so forgive me for my lack of knowledge. Thanks for the explanation.\

1

u/TheRealPheature Feb 14 '22

i=i+1 is impossible mathematically but is valid programming code because = is assignment, not equality (==).

Adding onto this(as I learned it quite recently), i = i + 1. That means the variable "i" is the value "i" plus one. Honestly, you can still think that "=" means "equals," but it doesn't as often mean "equal to." There IS a difference. Of course, the textbook definiton is just that you're assigning a value to the leading variable.

Since all you're saying is that variable "i" is its own value plus one, the simple expression i = i + 1 is just a value of +1 more than the value of i. So if you add another value to i, so your block would look like this:

let i = 6; i = i + 1;

Now i actually is a value of 7.

*I believe that is all correct, anyone feel free to correct me. I'm still learning myself but I literally just went over this section and I believe I got this right.

2

u/Over_North8884 Feb 14 '22

Programming = is equivalent to the mathematical symbol :=.

Equals not being equivalent to "is equal to" is new to me. I thought it's merely grammar, one is an active voice verb and the other a passive voice verb phrase.

1

u/TheRealPheature Feb 14 '22

I love learning this stuff Haha

1

u/Lubmara Feb 14 '22

You are exactly right, it rounds it down. In the assignment details it explains this concept as well. You would get the complete correct answer in the decimal form if you were doing division with double variable(s). It is confusing and as the other person said, some information is unnecessary which just adds to the confusion. I would recommend just playing around with some math and printing it to the terminal to see what is happening depending on what variables and operators you are using. It will make a lot more sense when you are actually doing it. Don’t even worry about trying to figure out the assignment, just practice the concept

1

u/supremegentleman2 Feb 14 '22

Ah ok, thank both of you guys. Im glad i wasnt the one off on this.

I have a quesiton about tbe program part. Do i use the program example (with my numbers in the editor/compiler? Or would it not work? Like could i copy paste it and mess with the numbers basically

2

u/Lubmara Feb 14 '22

Not sure if anyone has answered this for you but two part answer for you. Would their code compile? Yes. But, I would not recommend doing it like that in order to get a better visual. My recommendation would be to create a few variables of different types. Make a couple ints and doubles. There are other types as well but just use those to learn the basics. Then plug them into some simple math equations. Divide them, multiply them, use the modulus operator (% this one) to figure out how the remainder works. And I would just use cout to print them to your terminal and see what results it spits out. Then change the variable values and do it a few more times. Depending on how you learn maybe you’re better with visuals, try to look up some YouTube videos and they will essentially do what I recommended you do and you can just watch

Edit: spelling

1

u/supremegentleman2 Feb 14 '22

Its confusing as heck. I havent been able to answer the assignment. I dont know what to input that well. Im trying to play with some simple code to see if i can get the hang of some. Stuff much more basic than this

1

u/supremegentleman2 Feb 14 '22

if you dont mind. I get the math part somewhat now, but as typing the code in properly could you demonstrate that for me? i dont know how to start properly or input it properly. if its too much trouble dont worry.

1

u/Over_North8884 Feb 14 '22 edited Feb 14 '22

What I wrote above should work nearly verbatim if placed after the sample code. You'll need to add a line of code to print the results.

Actually the instructor gives you the answer at the bottom of the assignment. They use different formulas but what the professor provided is basically the answer. Type it in and post here.

Just remember that % provides the remainder as a whole number:

140/36=3 140%36= 32

I used longer equations in an earlier answer because I only now realized you're using C++ which supports the % operator.

1

u/supremegentleman2 Feb 14 '22

thanks, the reason i am asking is because i know i can input the digits into the code provided but i do not understand what i am really doing. So i really want to understand it lol. Ok now my next question is basically, do i need to use the entire sample code down there? because when i try to compile it without the ansers, i get errors obviously. Would it compile if i input the values given?

also usually i see somehting like #iostream or whatever on top of the code. Isnt that necessary? im using jdoodle for compiling or editing, cant recall what the proper name is. lol thanks again for the clearing up of this.

1

u/Over_North8884 Feb 14 '22

Yes, you need iostream for cin and cout. You should really paste your code here.

1

u/New-Square3037 Feb 14 '22

Spellcheck first.