โปรแกรมขายน้ำ ภาษาC++

กระทู้คำถาม
#include <iostream>

using namespace std;

int main(int argc, char** argv) {
    int i=0;
    int r=0;
    int price=0;
    int money=0;
    int sum1[100];
    int total=0;
    int sum_s=0;
    int sum_P=0;
    int sum_p=0;
    int sum_c=0;
    int sum_w=0;
    int q1 =0;
    int q2 =0;
    int q3 =0;
    int q4 =0;
    int q5 =0;
    
    
    while(1){
        cout << "1.Water             8 baht" << endl;
        cout << "2.Pepsi            10 baht" << endl;
        cout << "3.Pepsi Size big   15 baht" << endl;
        cout << "4.Coke             12 baht" << endl;
        cout << "5.sprite           12 baht" << endl;
        cout << "0.Payment" << endl;
        cout << endl;
        cout << "Select Menu 0-5 Please" << endl;
        cout << "-------------------------------------------------" << endl;    
        cout << "Menu : ";
        cin >> r;
        sum1=0;
        if(r==1)
        {
            price=8;
            cout << "Quality : " ;
            cin >> q1;
            sum_w = sum_w + q1;
            q1 = q1*price;
            sum1=sum1+q1;
            cout << "Total : "<< q1 << " bath" << endl;
            cout << "------------------------------------------" << endl;
            i++;
        }
        else if(r==2)
        {
            price=10;
            cout << "Quality : " ;
            cin >> q2;
            sum_p = sum_p + q2;
            q2 = q2*price;
            sum1=sum1+q2;
            cout << "Total : "<< q2 << " bath" << endl;
            cout << "------------------------------------------" << endl;
            i++;
        }
        else if(r==3)
        {
            price=15;
            cout << "Quality : " ;
            cin >> q3;
            sum_P = sum_P + q3;
            q3 = q3*price;
            sum1=sum1+q3;
            cout << "Total : "<< q3 << " bath" << endl;
            cout << "------------------------------------------" << endl;
            i++;
        }
        else if(r==4)
        {
            price=12;
            cout << "Quality : " ;
            cin >> q4;
            sum_c = sum_c + q4;
            q4 = q4*price;
            sum1=sum1+q4;
            cout << "Total : "<< q4 << " bath" << endl;
            cout << "------------------------------------------" << endl;
            i++;
        }
        else if(r==5)
        {
            price=12;
            cout << "Quality : " ;
            cin >> q5;
            sum_s = sum_s + q5;
            q5 = q5*price;
            sum1=sum1+q5;
            cout << "Total : "<< q5 << " bath" << endl;
            cout << "------------------------------------------" << endl;
            i++;
        }    
        else if(r==0)
        {   
            for(int j=0;j<i;j++){
                total = total + sum1[j];    
            }
            cout << "Water              \t: " << sum_w << "      Price :" << q1 <<  "    Bath" << endl;
            cout << "Pepsi              \t: " << sum_p << "      Price :" << q2 <<  "    Bath" << endl;
            cout << "Pepsi Size big     \t: " << sum_P << "      Price :" << q3 <<  "    Bath" << endl;
            cout << "Coke               \t: " << sum_c << "      Price :" << q4 <<  "    Bath" << endl;
            cout << "Sprite             \t: " << sum_s << "      Price :" << q5 <<  "    Bath" << endl;
            cout << endl;
            cout << "Total : " << total << endl;
            cout << endl;
            do{
                cout << "Money : ";
                cin >> money;
                if(money<total)
                    cout << "!!!!Input New money Please!!!!" << endl;
            }while(money<total);
            cout << "Blance : " << money-total << endl;
            break;
        }
        else
        {
            cout << "!!put on number 0-5!!"<<endl;
        }        
}

    return 0;
}
ช่วยอภิบายโค้ดแต่ละบรรทัดให้หน่อย ว่าแต่ละบรรทัดมันคืออะไร
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่