Tuesday, July 14, 2009

C++ Program?

I'm having a problem with my assignment. I can't get the program to do what it's suppose to do. Here is the thing I'm suppose to make.





Suppose you have a group of people who need to be transported on buses and vans. You can chargter a bus only if you can fill it. Each bus holds 50 people. You must provide enough vans for the 49 or fewer people who will be left over after you charter buses. Whrite a programthat accepts a number of people left over that must be placed on vans.





I can't get the modulus operator to work.





Here is what I have done so far:





//Project.cpp


#include %26lt;iostream.h%26gt;


#include %26lt;stdlib.h%26gt;


main()


{


const int size=50; //Declare size as a constant


int number_of_people;


int total;


int r;


//Total number of people


cout %26lt;%26lt; "What is the total number of people";


cin %26gt;%26gt; number_of_people;


total=number_of_people/size;


r=number_of_people%size;


cout %26lt;%26lt;"The total number of buses is ...

C++ Program?
1st the code is not complete


and i want to know what is the use of r


if r is the number of buses then u must use the divide sign"/" not the moduls sign "%"


if u r using r as the number of people remaning


then it must be in the form


r=number_of_people-(total*size);


note:the above line will give the right nswer because u r using int for total na dint for size, but if u use float it will not work and r will be zero


i hope this have solved ur problem
Reply:It's all good.





'total ' is the number of buses.


'r' is the number of poeple left who must go in vans.





Sample: 190 people = 3 busses (150 people) and 190%50 is 40 (same as 190-150 which you would expect).
Reply:Did you add ( } ) mark for your maiin() frame?
Reply:replace the line:


int total;


with this line:


float total;





the reason is that you can not store a float value in an integer which is what you are doing here:


total=number_of_people/size;


No comments:

Post a Comment