mercredi 20 janvier 2016

FOR loop doesn't work properly

I'm new in C++. I'm trying to find my mistake in FOR loop. It doesn't work properly.

#include <iostream>
using namespace std;

int main() {

    int boxes;
    int boxes_for_sale;

    cout << "Enter quantity of the boxes in warehouse: > " << flush;
    cin >> boxes;
    cout << "Enter quantity of the boxes for sale: > " << flush;
    cin >> boxes_for_sale;

    for (int i = 1;; i++) {

        if (boxes < boxes_for_sale) {
            cout << "There are not enough boxes in warehouse!" << endl;
            cout << "Enter quantity of the boxes for sale: > " << flush;
            cin >> boxes_for_sale;
        }
        else
            boxes -= boxes_for_sale;
            cout << "Car N:" << i << " is full\n" << "You have " << boxes << "boxes for sale" << endl;

        if (boxes == 0)
            cout << "Sold out!" << endl;
            break;

    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire