Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,105 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,698 people online right now. Registration is fast and FREE... Join Now!




c++ help with left over numbers

 
Reply to this topicStart new topic

c++ help with left over numbers, i am trying to do a division and i need help

what animal are you
which of these animals are you
wolf [ 0 ] ** [0.00%]
dragon [ 1 ] ** [25.00%]
fox [ 0 ] ** [0.00%]
cat [ 0 ] ** [0.00%]
mix [ 0 ] ** [0.00%]
i am somthing ealse [ 1 ] ** [25.00%]
dragon and wolf with alot af magic [ 2 ] ** [50.00%]
Total Votes: 4
Guests cannot vote 
chiakko7
12 Oct, 2007 - 06:33 AM
Post #1

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 28


My Contributions
i am trying to do a math problem
CODE
#include <stdio.h>

main()
{
  int a,b,c;
   printf("total number of people ");
   scanf("%d",&a);
   b=a/50;
    printf("total charter buses %d\n",b);
    c=
    printf ("total vans %d\n",c);
   system ("pause");
   return 0;
   }

if i put in 345 it says i need 60 buses thats right but i need to make some thing added on that will tell how many people need vans can you help?
User is offlineProfile CardPM
+Quote Post

Gizmo
RE: C++ Help With Left Over Numbers
12 Oct, 2007 - 06:40 AM
Post #2

New D.I.C Head
*

Joined: 4 Oct, 2007
Posts: 36


My Contributions
Not sure if I understand exactly what you are looking for, but you can use the modulus % operator instead of dividing to return a remainder. Then you will need to determine how many people can ride in each van and calculate that.
User is offlineProfile CardPM
+Quote Post

chiakko7
RE: C++ Help With Left Over Numbers
12 Oct, 2007 - 06:50 AM
Post #3

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 28


My Contributions
QUOTE(Gizmo @ 12 Oct, 2007 - 07:40 AM) *

Not sure if I understand exactly what you are looking for, but you can use the modulus % operator instead of dividing to return a remainder. Then you will need to determine how many people can ride in each van and calculate that.

thanks gizmo if i figure it out i will post it up here so if some one ealse comes along needing it the can have it

This post has been edited by chiakko7: 12 Oct, 2007 - 06:50 AM
User is offlineProfile CardPM
+Quote Post

Louisda16th
RE: C++ Help With Left Over Numbers
12 Oct, 2007 - 07:20 AM
Post #4

 
Group Icon

Joined: 3 Aug, 2006
Posts: 1,790



Thanked: 1 times
Dream Kudos: 755
My Contributions
Just curious. Why do you put polls in all your topics?!
User is offlineProfile CardPM
+Quote Post

chiakko7
RE: C++ Help With Left Over Numbers
12 Oct, 2007 - 07:29 AM
Post #5

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 28


My Contributions
okay i need to make a insert that will allow me to put any thing under 50 in the line with the vans
CODE
#include <stdio.h>

main()
{
  int a,b,c;
   printf("total number of people ");
   scanf("%d",&a);
   b=a/50;
    printf("total charter buses %d\n",b);
    printf ("total vans %d\n",c);
   system ("pause");
   return 0;
   }

the b is right i just need some thing to move the left over to the van say if i had 140 people then [printf("total charter buses %d\n",b.); ]should pop up 2 and it dose but it cuts out the 40 i need away to move the 40 left over to [printf ("total vans %d\n",c);]
can you think of any thing?c=?



QUOTE(Louisda16th @ 12 Oct, 2007 - 08:20 AM) *

Just curious. Why do you put polls in all your topics?!

becase i like doing thim and it fun to see how people respond

This post has been edited by chiakko7: 12 Oct, 2007 - 07:30 AM
User is offlineProfile CardPM
+Quote Post

aceofspades686
RE: C++ Help With Left Over Numbers
12 Oct, 2007 - 07:40 AM
Post #6

D.I.C Regular
Group Icon

Joined: 8 Oct, 2007
Posts: 261


Dream Kudos: 100
My Contributions
Depending on how many people are in the vans, you would need to divide a%50 by that. For example assuming that you were looking to fit 20 people per van it would be c=(a%50)/20.
User is offlineProfile CardPM
+Quote Post

chiakko7
RE: C++ Help With Left Over Numbers
12 Oct, 2007 - 07:50 AM
Post #7

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 28


My Contributions
QUOTE(aceofspades686 @ 12 Oct, 2007 - 08:40 AM) *

Depending on how many people are in the vans, you would need to divide a%50 by that. For example assuming that you were looking to fit 20 people per van it would be c=(a%50)/20.

it did not work is there any way to get i where c=a????????
so that the left overs form any thing from 1-49 will go to c after the buses fill up

This post has been edited by chiakko7: 12 Oct, 2007 - 07:54 AM
User is offlineProfile CardPM
+Quote Post

chiakko7
RE: C++ Help With Left Over Numbers
12 Oct, 2007 - 07:55 AM
Post #8

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 28


My Contributions

QUOTE(aceofspades686 @ 12 Oct, 2007 - 08:40 AM) *

Depending on how many people are in the vans, you would need to divide a%50 by that. For example assuming that you were looking to fit 20 people per van it would be c=(a%50)/20.

it did not work is there any way to get i where c=a????????
so that the left overs form any thing from 1-49 will go to c after the buses fill up
or do you have the thing for "modulus operator" idk what that is

This post has been edited by chiakko7: 12 Oct, 2007 - 07:57 AM
User is offlineProfile CardPM
+Quote Post

chiakko7
RE: C++ Help With Left Over Numbers
12 Oct, 2007 - 08:17 AM
Post #9

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 28


My Contributions
QUOTE(chiakko7 @ 12 Oct, 2007 - 08:55 AM) *

QUOTE(aceofspades686 @ 12 Oct, 2007 - 08:40 AM) *

Depending on how many people are in the vans, you would need to divide a%50 by that. For example assuming that you were looking to fit 20 people per van it would be c=(a%50)/20.

it did not work is there any way to get i where c=a????????
so that the left overs form any thing from 1-49 will go to c after the buses fill up
or do you have the thing for "modulus operator" idk what that is

help
anyone?
sigh
fine bye:'(
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: C++ Help With Left Over Numbers
12 Oct, 2007 - 11:08 AM
Post #10

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
ok, to put a new spin on it.

Lets say that 50 people can fit on a bus

numBusses = people/50;
peopleLeftOver = people % 50;

so after we pack the buses we now have some people with no ride. lets suppose that 10 people fit in a van (9 in the back, 1 shotgun -- not counting driver).

numVans = peopleLeftOver/10;
peopleLeftBehind = peopleLeftOver % 10;

ok, if we pack all the vans filled we may still have some people who can't fit. Here we can either add an extra van or take cars. If we take an extra van we need to check is one is needed:

if (peopleLeftBehind > 0) { numVans++; }

if we just wanted to take cars then we would just do the same as before:

numCars = peopleLeftBehind/4;
if (peopleLeftBehind % 4 > 0) { numCars++; }



User is offlineProfile CardPM
+Quote Post

chiakko7
RE: C++ Help With Left Over Numbers
16 Oct, 2007 - 05:30 AM
Post #11

New D.I.C Head
*

Joined: 8 Oct, 2007
Posts: 28


My Contributions
QUOTE(NickDMax @ 12 Oct, 2007 - 12:08 PM) *

ok, to put a new spin on it.

Lets say that 50 people can fit on a bus

numBusses = people/50;
peopleLeftOver = people % 50;

so after we pack the buses we now have some people with no ride. lets suppose that 10 people fit in a van (9 in the back, 1 shotgun -- not counting driver).

numVans = peopleLeftOver/10;
peopleLeftBehind = peopleLeftOver % 10;

ok, if we pack all the vans filled we may still have some people who can't fit. Here we can either add an extra van or take cars. If we take an extra van we need to check is one is needed:

if (peopleLeftBehind > 0) { numVans++; }

thank you it worked perfectly wink2.gif
sorry i am long in responding i am not allowed on the computer at home becase of grades
(not that it stops me when my parents are not home biggrin.gif

if we just wanted to take cars then we would just do the same as before:

numCars = peopleLeftBehind/4;
if (peopleLeftBehind % 4 > 0) { numCars++; }


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:08PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month