## Trouble with introductory programming with C program regarding division and modulus

difference between modulus and division in c
modulus and division in java
modulus operator in c examples
integer division programming
mod c
division operator in c
c modulus negative
integer division calculator

I apologize for the poor title, and I wish to be more specific, however I am in an introductory programming course, and I don't have much programming experience. The problem I have been given states that I need to find the total amount of rope to climb a mountain. It has to accurately put out how many pieces of 100 feet rope are needed, and how many 10 feet pieces of rope are needed. The issue I'm facing is that when, say for example, the mountain is 611 feet, I'm unsure how to get the program to display that 6 pieces of 100 feet rope are needed and 2 pieces of 10 feet rope are needed. My code allows for simple figures like, 600, or 610, or 10 feet, but I don't know how to compensate for a figure that is in between tens. My code is placed below- Again, I apologize for not being able to make this more specific.

```#include <stdio.h>

int main() {
// declaration of variables
int total_height;
int hundred_feet_rope;
int ten_feet_rope;

//prompt user for input information
printf("How tall is the mountain?\n");
scanf("%d", &total_height);

//calculations for how many skeins of 100 feet rope are needed, and how many 10 feet rope is needed
hundred_feet_rope = total_height / 100;
ten_feet_rope = total_height % 100 / 10;

//output results
printf("You will need %d skeins of 100 feet rope and %d skeins of 10 feet rope!\n", hundred_feet_rope, ten_feet_rope);

return 0;
}
```

Modulo Operator (%) in C/C++ with Examples, The modulo division operator produces the remainder of an integer division. Compilation Error in C code :- prog.c: In function 'main': prog.c:19:16: error: invalid The sign of the result for modulo operator is machine-dependent for negative Please write to us at contribute@geeksforgeeks.org to report any issue with the  Trouble with introductory programming with C program regarding division and modulus I apologize for the poor title, and I wish to be more specific, however I am in an introductory programming course, and I don't have much programming experience.

To consume the additional 10-foot section of rope you require for anything between multiples of 10, you must push your existing number to account for that additional length of rope prior to the final division.

```ten_feet_rope = (total_height % 100 + 9) / 10;
// here ============================^^^
```

This is common in computer science. Ex: symmetric encryption of an arbitrary amount of data using a specified block size .

At least I think that's what you're asking. I leave the task of accounting for this potentially bleeding into a 100 foot multiple to you (it can happen. suppose you had a 95 foot height; in that case you would want one 100ft length, and no 10ft lengths).

An Introduction to C Programming for First-time Programmers, Let's begin by writing our first C program that prints the message "Hello, world!" on the On Text Editor with GNU GCC compiler, issue these command from CMD Shell Addition, subtraction, multiplication, division and remainder are binary  For the Love of Physics - Walter Lewin - May 16, 2011 - Duration: 1:01:26. Lectures by Walter Lewin. They will make you ♥ Physics. Recommended for you

You could use the modulus operator to see if the remaining number divided by 10 is bigger than 0, if so, it adds one 10 feet rope:

```if (total_height % 10 > 0)
ten_feet_rope++;
```

Integer Division and Modulus – Programming Fundamentals, Practice: Introduction to Programming In integer division and modulus, the dividend is divided by the divisor into an integer quotient and a remainder. differently, depending on the programming language, and is called: integer division. cnx.org: Programming Fundamentals – A Modular Structured Approach using C++  The C and C++ language provides a built-in mechanism, the modulus operator (‘%’), that computes the remainder that results from performing integer division. Consider the following program which takes a number from user and calculates the remainder of the number with divided by 3.

A Natural Introduction to Computer Programming with C++, Program evenodd.cpp is another example of the use of an if-else construct. As there are only two possible values for the remainder in by-two divisions, the  The modulus operator in C gives us the remainder. Thus, a%b gives us the remainder after dividing a by b. When we divide a smaller number by a larger number, the quotient is zero, while the remainder is the dividend i.e. the smaller number itself. So, the result is the smaller number itself, no matter how much larger the divisor is.

Modulus Operator in C and C++, How to use the modulus operator when in C and C++ to get remainders. Take a simple arithmetic problem: what's left over when you divide 11 by 3? But how would you compute this in a programming language like C or C++? It's not generated number and reduce that number to a random number on a smaller range,  C PROGRAMMING: INTEGER DIVISION AND MODULO (%) Whentwointegersaredivided,theresultistruncated. Thatis,whenthecomputercalculates 23/4, instead of getting 5.75 it gets 5. The computer literally asks how many times 4 goes into 23, and doesn’t care anything about the remainder.

Introduction to Numerical Programming: A Practical Guide for , A Practical Guide for Scientists and Engineers Using Python and C/C++ Titus A. Beu According to the polynomial remainder theorem, by dividing Pn (x) by the while Listing 6.11 provides an example of a main program that makes use of  Check out http://www.engineer4free.com for more free engineering tutorials and math lessons! C++ Programming Tutorial: Integer division and remainders using

##### Comments
• `total_height % 10` is zero when the height is divisible by 10 and not zero if the height isn’t divisible by 10. Does that help?
• 5 100 and 9 10 will not be enough anyway. Did you mean 5 100 and 10 10?
• @Broman: yes, good catch! I was fixing it as you were commenting :)
• This will fail an input on the form `x99` where `x` is zero or more digits.
• @Broman Did you read this answer? Specifically the last sentence ?
• Nope, I did not. I stopped reading when I saw the bug. Good enough then.
• This was it, thank you so much. I feel i overthought the problem a lot looking back on it. Again, i apologize if the question was worded poorly or if the code wasn't formatted accurately.
• @MorganHilton Read the last sentence. You still have work to do. But at least you know how to round up to a nearest block, which I think was the root of your question.This answer isn't intended to solve your homework; only show you how to do that round-up.