Validation of Quantity in C ++

0

Buenos Dias, I have the following exercise in which I want to validate the amount "cropa" that is only between 0 and 100, and if you go over these quantities, ask me again without finding any problem with the rest of the calculations .

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

using namespace std;

int main(int argc, char const *argv[])
{
    char nombre[30];
    char servicio, resp = 's';
    int ccliente = 0;
    float ttotal = 0;
    const float lavado = 1550, lavsec = 2570, planchado = 3000, tenido = 3500;
    float cropa, iva, subtotal, total;

    do{

        ccliente++;
        system("cls");
        cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
        cout<<"\n\nNombre del Cliente: "<<ccliente;
        cin>>nombre;
        cout<<"\nCantidad de Kgs de Ropa: ";
        cin>>cropa;
        if(cropa <= 0 || cropa >= 100){
            cout<<"Cantidad Invalida, Intente Nuevamente";
        }
        else{
        cout<<"\nTipos de Servicio:";
        cout<<"\n\nTipo A: Lavado (Bs. 1550)";
        cout<<"\n\nTipo B: Lavado y Secado (Bs. 2570)";
        cout<<"\n\nTipo C: Planchado (Bs. 3000)";
        cout<<"\n\nTipo D: Teñido (Bs. 3500)";
        cout<<"\n\nTipo a Seleccionar: ";
        cin>>servicio;
        }

        switch (servicio)
        {

        case 'a': case 'A':

            system("cls");
            cout<<fixed<<setprecision(2);
            cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
            cout<<"\n\nCliente: "<<nombre;
            cout<<"\nCantidad de Kgs de Ropa: "<<cropa;
            cout<<"\n\nTipo A: L A V A D O";
            subtotal = cropa * lavado;
            iva = subtotal * 12/100;
            total = subtotal + iva;
            cout<<"\n\nSubtotal: Bs. "<<subtotal;
            cout<<"\nIVA (12%): Bs. "<<iva;
            cout<<"\n\nTotal a Pagar: Bs. "<<total;
            break;

        case 'b': case 'B':

            system("cls");
            cout<<fixed<<setprecision(2);
            cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
            cout<<"\n\nCliente: "<<nombre;
            cout<<"\nCantidad de Kgs de Ropa: "<<cropa;
            cout<<"\n\nTipo B: L A V A D O y S E C A D O";
            subtotal = cropa * lavsec;
            iva = subtotal * 12/100;
            total = subtotal + iva;
            cout<<"\n\nSubtotal: Bs. "<<subtotal;
            cout<<"\nIVA (12%): Bs. "<<iva;
            cout<<"\n\nTotal a Pagar: Bs. "<<total;
            break;

        case 'c': case 'C':

            system("cls");
            cout<<fixed<<setprecision(2);
            cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
            cout<<"\n\nCliente: "<<nombre;
            cout<<"\nCantidad de Kgs de Ropa: "<<cropa;
            cout<<"\n\nTipo C: P L A N C H A D O";
            subtotal = cropa * planchado;
            iva = subtotal * 12/100;
            total = subtotal + iva;
            cout<<"\n\nSubtotal: Bs. "<<subtotal;
            cout<<"\nIVA (12%): Bs. "<<iva;
            cout<<"\n\nTotal a Pagar: Bs. "<<total;
            break;

        case 'd': case 'D':

            system("cls");
            cout<<fixed<<setprecision(2);
            cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
            cout<<"\n\nCliente: "<<nombre;
            cout<<"\nCantidad de Kgs de Ropa: "<<cropa;
            cout<<"\n\nTipo D: T E Ñ I D O";
            subtotal = cropa * tenido;
            iva = subtotal * 12/100;
            total = subtotal + iva;
            cout<<"\n\nSubtotal: Bs. "<<subtotal;
            cout<<"\nIVA (12%): Bs. "<<iva;
            cout<<"\n\nTotal a Pagar: Bs. "<<total;
            break;

        default:

            cout<<"Opcion Invalida, Intente Nuevamente";
            ccliente--;
            ttotal = ttotal - total;
        }

        ttotal = ttotal + total;

        cout<<"\n\nDesea Procesar un Nuevo Cliente (S/N): ";
        cin>>resp;

    }while (resp == 's' || resp == 'S');

    system("cls");
    cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
    cout<<"\n\nTotal de Clientes: "<<ccliente;
    cout<<"\nTotal Facturado: Bs. "<<ttotal;

    return 0;
}

With the If, you can do it but only with the first client, then if you successfully enter a client, and I want to enter another one and you want to validate it happens to the invoice and add that invalid client.

How could I solve it?

Greetings!

    
asked by Carlos Agustin Guanipa Alvarez 07.04.2017 в 16:02
source

2 answers

0

There are several ways this occurred to me, I hope you serve

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

using namespace std;

int main(int argc, char const *argv[])
{
 char nombre[30];
 char servicio, resp = 's';
 int ccliente = 0;
 float ttotal = 0;
 const float lavado = 1550, lavsec = 2570, planchado = 3000, tenido = 3500;
 float cropa=0, iva, subtotal, total;

 do{

    ccliente++;
    system("cls");
    cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
    cout<<"\n\nNombre del Cliente: "<<ccliente;
    cin>>nombre;
    cout<<"\nCantidad de Kgs de Ropa: ";
    cin>>cropa;



        while(cropa <= 0 || cropa >=100){
        cout<<"Cantidad Invalida, Intente Nuevamente";
         cout<<"\nCantidad de Kgs de Ropa: ";
        cin>>cropa;

         }



            cout<<"\nTipos de Servicio:";
            cout<<"\n\nTipo A: Lavado (Bs. 1550)";
            cout<<"\n\nTipo B: Lavado y Secado (Bs. 2570)";
            cout<<"\n\nTipo C: Planchado (Bs. 3000)";
            cout<<"\n\nTipo D: Teñido (Bs. 3500)";
            cout<<"\n\nTipo a Seleccionar: ";
            cin>>servicio;








    switch (servicio)
    {

    case 'a': case 'A':

        system("cls");
        cout<<fixed<<setprecision(2);
        cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
        cout<<"\n\nCliente: "<<nombre;
        cout<<"\nCantidad de Kgs de Ropa: "<<cropa;
        cout<<"\n\nTipo A: L A V A D O";
        subtotal = cropa * lavado;
        iva = subtotal * 12/100;
        total = subtotal + iva;
        cout<<"\n\nSubtotal: Bs. "<<subtotal;
        cout<<"\nIVA (12%): Bs. "<<iva;
        cout<<"\n\nTotal a Pagar: Bs. "<<total;
        break;

    case 'b': case 'B':

        system("cls");
        cout<<fixed<<setprecision(2);
        cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
        cout<<"\n\nCliente: "<<nombre;
        cout<<"\nCantidad de Kgs de Ropa: "<<cropa;
        cout<<"\n\nTipo B: L A V A D O y S E C A D O";
        subtotal = cropa * lavsec;
        iva = subtotal * 12/100;
        total = subtotal + iva;
        cout<<"\n\nSubtotal: Bs. "<<subtotal;
        cout<<"\nIVA (12%): Bs. "<<iva;
        cout<<"\n\nTotal a Pagar: Bs. "<<total;
        break;

    case 'c': case 'C':

        system("cls");
        cout<<fixed<<setprecision(2);
        cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
        cout<<"\n\nCliente: "<<nombre;
        cout<<"\nCantidad de Kgs de Ropa: "<<cropa;
        cout<<"\n\nTipo C: P L A N C H A D O";
        subtotal = cropa * planchado;
        iva = subtotal * 12/100;
        total = subtotal + iva;
        cout<<"\n\nSubtotal: Bs. "<<subtotal;
        cout<<"\nIVA (12%): Bs. "<<iva;
        cout<<"\n\nTotal a Pagar: Bs. "<<total;
        break;

    case 'd': case 'D':

        system("cls");
        cout<<fixed<<setprecision(2);
        cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
        cout<<"\n\nCliente: "<<nombre;
        cout<<"\nCantidad de Kgs de Ropa: "<<cropa;
        cout<<"\n\nTipo D: T E Ñ I D O";
        subtotal = cropa * tenido;
        iva = subtotal * 12/100;
        total = subtotal + iva;
        cout<<"\n\nSubtotal: Bs. "<<subtotal;
        cout<<"\nIVA (12%): Bs. "<<iva;
        cout<<"\n\nTotal a Pagar: Bs. "<<total;
        break;

    default:

        cout<<"Opcion Invalida, Intente Nuevamente";
        ccliente--;
        ttotal = ttotal - total;
    }

    ttotal = ttotal + total;

    cout<<"\n\nDesea Procesar un Nuevo Cliente (S/N): ";
    cin>>resp;

}while (resp == 's' || resp == 'S');

system("cls");
cout<<"< = = = = = LAVANDERIA C L E A N = = = = = >";
cout<<"\n\nTotal de Clientes: "<<ccliente;
cout<<"\nTotal Facturado: Bs. "<<ttotal;

return 0;

}

    
answered by 07.04.2017 / 16:23
source
1

You have to change the

   if(cropa <= 0 || cropa >= 100)
        {
            cout<<"Cantidad Invalida, Intente Nuevamente";
        }
        else
        {
        cout<<"\nTipos de Servicio:";
        cout<<"\n\nTipo A: Lavado (Bs. 1550)";
        cout<<"\n\nTipo B: Lavado y Secado (Bs. 2570)";
        cout<<"\n\nTipo C: Planchado (Bs. 3000)";
        cout<<"\n\nTipo D: Teñido (Bs. 3500)";
        cout<<"\n\nTipo a Seleccionar: ";
        cin>>servicio;
        }

For a

while (cropa <= 0 || cropa >= 100)
        {
            cout<<"Cantidad Invalida, Intente Nuevamente";
            cin>>cropa;
        }
        cout<<"\nTipos de Servicio:";
        cout<<"\n\nTipo A: Lavado (Bs. 1550)";
        cout<<"\n\nTipo B: Lavado y Secado (Bs. 2570)";
        cout<<"\n\nTipo C: Planchado (Bs. 3000)";
        cout<<"\n\nTipo D: Teñido (Bs. 3500)";
        cout<<"\n\nTipo a Seleccionar: ";
        cin>>servicio;

Since if you enter it incorrectly it will skip the next client, this way you will stay in the same client until you enter the correct amount.

    
answered by 07.04.2017 в 16:10