Doubt with Nested Cycle Exercise C ++

1

Good afternoon, in the following exercise, if I want to serve two people for example, when asking for the first data and what you are going to buy, you do not throw the invoice, but you throw it with the last one or this case In the latter case, it also combines the data and does not do it individually for one.

It should be noted that there are still several cases that need to be worked out in the program and, in addition, to print the total sold and attended to, but at the moment this doubt does not allow me to continue.

    #include "iostream"
    #include "stdio.h"
    #include "math.h"
    #include "stdlib.h"
    #include "iomanip"

    using namespace std;

    int main(int argc, char const *argv[])
    {
    int i, n, cn = 0, combo, c1, c2, c3;
    float combo1 = 8500, combo2 = 11700, combo3 = 15000;
    float descuento = 0, subtotal, total;
    char nombre[30], carnet = 's';

    cout<<"< = = = C L A P Edo. T A C H I R A = = = >";
    cout<<"\n\nCantidad de Personas para Atender: ";
    cin>>n;

    for(i = 0 ; i < n ; i++)
    {
        cn++;
        system("cls");
        cout<<"< = = = C L A P Edo. T A C H I R A = = = >";
        cout<<"\n\nNombre del Ciudadano: "<<cn;cout<<" ";
        cin>>nombre;
        cout<<"\nPosee Carnet de la Patria (S/N): ";
        cin>>carnet;

        if(carnet == 's' || carnet =='S')
        {
            system("cls");
            cout<<"< = = = C L A P Edo. T A C H I R A = = = >";
            cout<<"\n\nCombos Disponibles: ";
            cout<<"\n\nCombo 1 (Bs. 8500)";
            cout<<"\nCombo 2 (Bs. 11700)";
            cout<<"\nCombo 3 (Bs. 15000)";
            cout<<"\n\nCombo a Comprar: ";
            cin>>combo;

            switch (combo)
            {
                case 1:

                system("cls");
                cout<<"< = = = C L A P Edo. T A C H I R A = = = >";
                cout<<"\n\nCombo 1 (Bs. 8500)";
                cout<<"\n\nCantidad a Comprar: ";
                cin>>c1;

                subtotal = c1 * combo1;
                if(subtotal > 50000)
                    descuento = subtotal * 8.7/100;
                total = subtotal - descuento;

                system("cls");
                cout<<"< = = = C L A P Edo. T A C H I R A = = = >";
                cout<<"\n\n< - F A C T U R A - >";
                cout<<"\n\nCliente: "<<nombre;
                cout<<"\n\nSubtotal: Bs. "<<subtotal;
                cout<<"\nDescuento: Bs. -"<<descuento;
                cout<<"\n\nTotal a Pagar: Bs. "<<total;
                break;

                default:
                cout<<"Opcion Invalida, Intente Nuevamente";

            }

        }

    }


    return 0;
}
    
asked by Carlos Agustin Guanipa Alvarez 08.04.2017 в 20:08
source

1 answer

3

The variables always remain with the previous values, since they are not equal to 0 after doing the operations. (before returning to the for)

for(i = 0 ; i < n ; i++)
{ 
 /* Demás código  if swicth */
 if(carnet == 's' || carnet =='S'){....}
 switch (combo){ .... }
 /* Después del if y  switch , Igualamos a 0 las variables para que no 
    se quedé con los valores  de las operaciones anteriores */
  subtotal =0; total=0;descuento=0;
}
    
answered by 08.04.2017 / 20:17
source