c++ help with left over numbers

i am trying to do a division and i need help

Page 1 of 1

10 Replies - 3997 Views - Last Post: 16 October 2007 - 06:30 AM Rate Topic: -----

Poll: what animal are you (4 member(s) have cast votes)

which of these animals are you

  1. wolf (0 votes [0.00%])

    Percentage of vote: 0.00%

  2. dragon (1 votes [25.00%])

    Percentage of vote: 25.00%

  3. fox (0 votes [0.00%])

    Percentage of vote: 0.00%

  4. cat (0 votes [0.00%])

    Percentage of vote: 0.00%

  5. mix (0 votes [0.00%])

    Percentage of vote: 0.00%

  6. i am somthing ealse (1 votes [25.00%])

    Percentage of vote: 25.00%

  7. dragon and wolf with alot af magic (2 votes [50.00%])

    Percentage of vote: 50.00%

Vote Guests cannot vote

#1 chiakko7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 08-October 07

c++ help with left over numbers

Post icon  Posted 12 October 2007 - 07:33 AM

i am trying to do a math problem
#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?

Is This A Good Question/Topic? 0
  • +

Replies To: c++ help with left over numbers

#2 Gizmo   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 04-October 07

Re: c++ help with left over numbers

Posted 12 October 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.
Was This Post Helpful? 0
  • +
  • -

#3 chiakko7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 08-October 07

Re: c++ help with left over numbers

Posted 12 October 2007 - 07:50 AM

View PostGizmo, on 12 Oct, 2007 - 07:40 AM, said:

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 October 2007 - 07:50 AM

Was This Post Helpful? 0
  • +
  • -

#4 Louisda16th   User is offline

  • dream.in.assembly.code
  • member icon

Reputation: 15
  • View blog
  • Posts: 1,967
  • Joined: 03-August 06

Re: c++ help with left over numbers

Posted 12 October 2007 - 08:20 AM

Just curious. Why do you put polls in all your topics?!
Was This Post Helpful? 0
  • +
  • -

#5 chiakko7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 08-October 07

Re: c++ help with left over numbers

Posted 12 October 2007 - 08:29 AM

okay i need to make a insert that will allow me to put any thing under 50 in the line with the vans
#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=?



View PostLouisda16th, on 12 Oct, 2007 - 08:20 AM, said:

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 October 2007 - 08:30 AM

Was This Post Helpful? 0
  • +
  • -

#6 aceofspades686   User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 334
  • Joined: 08-October 07

Re: c++ help with left over numbers

Posted 12 October 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.
Was This Post Helpful? 0
  • +
  • -

#7 chiakko7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 08-October 07

Re: c++ help with left over numbers

Posted 12 October 2007 - 08:50 AM

View Postaceofspades686, on 12 Oct, 2007 - 08:40 AM, said:

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 October 2007 - 08:54 AM

Was This Post Helpful? 0
  • +
  • -

#8 chiakko7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 08-October 07

Re: c++ help with left over numbers

Posted 12 October 2007 - 08:55 AM

View Postaceofspades686, on 12 Oct, 2007 - 08:40 AM, said:

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 October 2007 - 08:57 AM

Was This Post Helpful? 0
  • +
  • -

#9 chiakko7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 08-October 07

Re: c++ help with left over numbers

Posted 12 October 2007 - 09:17 AM

View Postchiakko7, on 12 Oct, 2007 - 08:55 AM, said:

View Postaceofspades686, on 12 Oct, 2007 - 08:40 AM, said:

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:'(
Was This Post Helpful? 0
  • +
  • -

#10 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: c++ help with left over numbers

Posted 12 October 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++; }

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

numCars = peopleLeftBehind/4;
if (peopleLeftBehind % 4 > 0) { numCars++; }
Was This Post Helpful? 0
  • +
  • -

#11 chiakko7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 08-October 07

Re: c++ help with left over numbers

Posted 16 October 2007 - 06:30 AM

View PostNickDMax, on 12 Oct, 2007 - 12:08 PM, said:

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 ;)
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 :D

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

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1