Buenas Noches, tengo el siguiente ejercicio en el que pido una respuesta y existen dos opciones (S/N), S o N (si o no), el programa va de maravilla sin embargo la validación de que solo sea S o N, no logro hacerla funcionar. Si pongo alguna otra letra que no sea S o N el programa sigue corriendo. Mi duda es como y donde hago al validación...
#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;
int c1total = 0, c2total = 0, c3total = 0;
float combo1 = 8500, combo2 = 11700, combo3 = 15000;
float descuento = 0, tdescuento= 0, subtotal, total, ttotal = 0, total_neto;
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<<fixed<<setprecision(2);
cout<<"\n\n< = = = 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;
tdescuento = tdescuento + descuento;
c1total = c1total + c1;
ttotal = ttotal + total;
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;
case 2:
system("cls");
cout<<"< = = = C L A P Edo. T A C H I R A = = = >";
cout<<"\n\nCombo 2 (Bs. 11700)";
cout<<"\n\nCantidad a Comprar: ";
cin>>c2;
subtotal = c2 * combo2;
if(subtotal > 50000)
descuento = subtotal * 8.7/100;
total = subtotal - descuento;
tdescuento = tdescuento + descuento;
c2total = c2total + c2;
ttotal = ttotal + total;
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;
case 3:
system("cls");
cout<<"< = = = C L A P Edo. T A C H I R A = = = >";
cout<<"\n\nCombo 3 (Bs. 15000)";
cout<<"\n\nCantidad a Comprar: ";
cin>>c3;
subtotal = c3 * combo3;
if(subtotal > 50000)
descuento = subtotal * 8.7/100;
total = subtotal - descuento;
tdescuento = tdescuento + descuento;
c3total = c3total + c3;
ttotal = ttotal + total;
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";
cn--;
}
subtotal = 0;
descuento = 0;
total = 0;
}else
if(carnet == 'n' || carnet == 'N')
{
system("cls");
cout<<"< = = = C L A P Edo. T A C H I R A = = = >";
cout<<"\n\nCombo 3 (Bs. 15000)";
cout<<"\n\nCantidad a Comprar: ";
cin>>c3;
if(c3 >= 2)
{
cout<<"\nSolo puede Comprar Uno";
cout<<"\nLe Invitamos a Sacarse el Carnet de la Patria";
cout<<"\n\nCantidad a Comprar: ";
cin>>c3;
}
total = c3 * combo3;
c3total = c3total + c3;
ttotal = ttotal + total;
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\nTotal a Pagar: Bs. "<<total;
}
}
system("cls");
cout<<"< = = = C L A P Edo. T A C H I R A = = = >";
cout<<"\n\nCantidad de Combo 1 Vendido: "<<c1total;
cout<<"\nCantidad de Combo 2 Vendido: "<<c2total;
cout<<"\nCantidad de Combo 3 Vendido: "<<c3total;
cout<<"\n\nTotal General Facturado: Bs. "<<ttotal;
cout<<"\n\nTotal Descontado: Bs. "<<tdescuento;
total_neto = ttotal - tdescuento;
cout<<"\n\nTotal en Ganancias: Bs. "<<total_neto;
return 0;
}