Jump to content

In need of help on easy problem

- - - - -

  • Please log in to reply
4 replies to this topic

#1
EarsAndtail

EarsAndtail

    Newbie

  • Members
  • Pip
  • 5 posts
Okay, so I'm reading C++ How to Program and I've came upon this problem that I don't really understand.

6.25 Write program segments that accomplish each of the following:

a) Calculate the integer part of the quotient when integer a is divided by integer b.

b)Calculate the integer remainder when integer a is divided by integer b.

Use the program pieces developed in (a) and (b) to write a function that inputs an integer between 1 and 32767 and prints it as a series of digits, each pair of which is separated by two spaces. For example, the integer 4562 should print as follows:


4 5 6 2

I think I know how to do the first part just use floor in <cmath>. I don't know how to do the second part though! Also I'm not sure how part a and b fit in with the last part, is part a and b supposed to be inputting numbers into this function?

Sorry for posting about such an easy problem I just couldn't figure it out.

#2
NastyDevil

NastyDevil

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
LOL I have the exact book you are using right in front of me!

So for part b the remainder is what you get left with after the division... So EX: 10/3=9 remainder is 1. EX: 11/3=9 remainder is 2. To get the remainder right away you use % EX: 10%3 = 1. So that is basically it for part (b)

For the next step you are trying to get the digits in any integer. By using the division and remainder functions you mad in (a) and (b) you should be able to figure out a function that will be able to accomplish that. Get started on it and let me know if you get stuck

#3
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1

EarsAndtail said:

Sorry for posting about such an easy problem I just couldn't figure it out.
It might be easy for some, but remember that everyone had to go through this and no one was born with knowledge.

And as EarsAndtail said, use division ( / ) for A and modulus ( % ) operator for B to so solve this.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#4
EarsAndtail

EarsAndtail

    Newbie

  • Members
  • Pip
  • 5 posts

NastyDevil said:

LOL I have the exact book you are using right in front of me!

So for part b the remainder is what you get left with after the division... So EX: 10/3=9 remainder is 1. EX: 11/3=9 remainder is 2. To get the remainder right away you use % EX: 10%3 = 1. So that is basically it for part (b)

For the next step you are trying to get the digits in any integer. By using the division and remainder functions you mad in (a) and (b) you should be able to figure out a function that will be able to accomplish that. Get started on it and let me know if you get stuck

Arrrgg I had it right the entire time but I was just confusing myself xD Thank you for the help!
Edit: Okay now I might be confused. Is it supposed to be 10/ 3 = 3 with a remainder of 1? As in part a would say 3 and part b would say 1?

Flying Dutchman said:

It might be easy for some, but remember that everyone had to go through this and no one was born with knowledge.

And as EarsAndtail said, use division ( / ) for A and modulus ( % ) operator for B to so solve this.

It's good to know that I can post on here without having to worry about people telling me to learn how to program xD And it was actually NastyDevil that said that not me.

#5
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
Didn't even see that mistake! Well, sorry about it, credit goes to NastyDevil. :)
A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users