Thread: If statements

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    Question If statements

    Hi, i am new to c++ and i am writing a program to calculate the number of buses, for a group of people so each bus can contain 50 people and the reamining people have to go in vans each can contain 6 people so here is the program;
    //THis program will determine the number of buses needed for a tour

    #include"stdafx.h"
    #include <iostream.h>

    void main()
    {
    int people, remainder, people_to_buses, vans;

    int buses= 50;


    cout<<"Enter the number of people?";
    cin>> people;

    //Calculate the buses needed
    people_to_buses = people / buses;
    remainder = people % buses;

    //output answer
    cout<<"Buses needed " <<people_to_buses<<"\n";


    //calculate # of vans needed
    vans=remainder/6;

    //output to user
    cout<<"The number of vans needed is";
    cout<<vans<<"\n";


    }

    Where do i put the if statement and how do i write it?

  2. #2
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    What conditions do you need the if statement to check for?

    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  3. #3
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    Ok, if you just need to check for the number of vans needed for the remainder of people, then try something like this:
    Code:
        //calculate # of vans needed 
        vans=remainder/6; 
    
        // if the remainder is not 0, then execute
        if ( (remainder % 6) != 0)
        {
            // add one more to the van count
            ++van;  // or van+=1;  or van = van + 1;
        }
    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  3. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  4. Class Function Members and If Statements
    By Team Shadow V2 in forum C++ Programming
    Replies: 10
    Last Post: 02-03-2005, 03:00 PM
  5. Switch statements for strings
    By cxs00u in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2002, 03:38 PM