Hello. I just made a program that request the number of graduates as input and then displays the number of tickets to be distributed to each graduates.
Can it be simplified again?
Second, decide on one style. Currently, you have a mix of tabs and spaces. It's a holy war to say which is better (no flame wars, pls), but one thing everyone agrees on is to stay consistent.
#include <iostream>
int main()
{
constint seats = 2000; // variable will not change; make it const
std::cout << "Enter number of graduates: ";
int graduates = seats; // (initialize graduates with an invalid number)
// if std::cin fails to receive input, this will be the default value now
std::cin >> graduates;
// (Personally I prefer to deal with bad logic first,
// then move onward with the good logic.
// just a personal preference, though.)
if (graduates <= 0 || graduates >= seats) // removed magic number
{
std::cout << "Not in range!" << std::endl;
}
else // we don't need further if-logic here
{
int tickets = seats/graduates; // put variables on the inner-most scope necessary
std::cout << "Each graduate gets " << tickets << " tickets" << std::endl;
}
return 0;
}