Categoría de Estructura Condicional Anidada
💻 Hacer un algoritmo que calcule el descuento según el monto de compra :
• Dar un 25% si el monto de compra es mayor o igual que 300.
• Dar un 20% si el monto de compra es mayor que 150 y menor que 300.
• No hay descuento si el monto es menor a 150.
Obtén el descuento de un monto según la condición.
Para este ejercicio evaluamos la primera condición :
Si el monto es mayor que 300 aplicamos el 25%; caso contrario realizamos una nueva consulta o consulta anidada para conocer si el monto se encuentra en el
rango de 150 a 300; para ello aplicaremos (monto > 150 y monto < 300), si se considera que se encuentra en ese rango se aplica el 20% de descuento,
caso contrario no se aplica ningún descuento, ya que se entiende que el monto es menor que 150.
ANÁLISIS DEL CÓDIGO
VARIABLES ENTRADA :
Monto = Guarda un monto ingresado por teclado.
Descuento = Guarda el descuento obtenido.
INGRESO : Se ingresan un monto de dinero.
PROCESO : Se compara si el monto es mayor a 300 dar el descuento del 25%; si el monto está entre 150 a 300 dar el 20%, si no, no hay descuento.
SALIDA : Mostrar el descuento obtenido.
Algoritmo programacion_work
Definir Monto, Descuento como Real;
Escribir "CALCULAR EL DESCUENTO SEGÚN EL MONTO DE COMPRA.";
Escribir " ";
Escribir Sin Saltar "Ingrese Monto : $";
Leer Monto;
Escribir " ";
Si Monto > 300 Entonces
Descuento <- Monto * 0.25;
Escribir "El Descuento es : $", Descuento;
SiNo
Si (Monto > 150) Y (Monto < 300) Entonces
Descuento <- Monto * 0.20;
Escribir "El Descuento es : $", Descuento;
SiNo
Escribir "No Hay Descuento";
FinSi
FinSi
FinAlgoritmo
print("DADO UN MONTO, CALCULAR EL DESCUENTO.")
monto = float(input("Ingrese Monto : "))
if monto > 300:
descuento = monto * 0.25
print("El Descuento es : ", descuento)
elif (monto > 150) and (monto < 300):
descuento = monto * 0.20
print("El Descuento es : ", descuento)
else:
print("No Hay Descuento")
#include<stdio.h>
int main() {
float descuento, monto;
printf("CALCULAR EL DESCUENTO RESPECTIVO.\n\n");
printf("Ingrese Monto : $");
scanf("%f",&monto);
if (monto>300) {
descuento = monto*0.25;
printf("El descuento es 25 porciento : $%.2f\n",descuento);
} else {
if ((monto > 150) && (monto < 300)) {
descuento = monto*0.20;
printf("El descuento es 20 porciento : $%.2f\n",descuento);
} else {
printf("No hay descuento\n");
}
}
return 0;
}
#include<iostream>
using namespace std;
int main() {
float descuento, monto;
cout << "CALCULAR EL DESCUENTO RESPECTIVO.\n\n";
cout << "Ingrese Monto : $";
cin >> monto;
if (monto>300) {
descuento = monto*0.25;
cout << "El Descuento es 25% : $" << descuento << endl;
} else {
if ((monto > 150) && (monto < 300)) {
descuento = monto*0.20;
cout << "El Descuento es 20% : $" << descuento << endl;
} else {
cout << "No Hay Descuento" << endl;
}
}
return 0;
}
using System;
using System.Collections.Generic;
using System.Text;
namespace programacion_work
{
class calcular_descuento
{
static void Main(string[] args)
{
double descuento, monto;
Console.WriteLine("CALCULAR EL DESCUENTO RESPECTIVO.\n");
Console.Write("Ingrese Monto : $");
monto = double.Parse(Console.ReadLine());
if (monto > 300)
{
descuento = monto * 0.25;
Console.WriteLine("\nEl Descuento es 25% : $" + descuento);
}
else
{
if ((monto > 150) && (monto < 300))
{
descuento = monto * 0.20;
Console.WriteLine("\nEl Descuento es 20% : $" + descuento);
}
else
{
Console.WriteLine("\nNo Hay Descuento");
}
}
Console.ReadLine();
}
}
}
package programacion_work;
import java.util.Scanner;
public class ver_descuento {
public static void main(String[] args) {
Scanner ingreso=new Scanner(System.in);
double MONTO, DESCUENTO;
System.out.print("CALCULAR EL DESCUENTO SEGÚN EL MONTO DE INGRESO.\n\n");
System.out.print("Ingrese Monto : ");
MONTO = Double.parseDouble(ingreso.next());
if(MONTO >= 300){
DESCUENTO = MONTO * 0.25;
System.out.println("EL DESCUENTO ES 25%: " + DESCUENTO);
}else{
if((MONTO > 150) && (MONTO < 300)){
DESCUENTO = MONTO * 0.2;
System.out.println("EL DESCUENTO ES 20%: " + DESCUENTO);
}else{
System.out.println("NO HAY DESCUENTO");
}
}
}
}
private void jBtn_CalcularActionPerformed(java.awt.event.ActionEvent evt) {
double MONTO, DESCUENTO;
MONTO = Integer.parseInt(jTxt_Monto.getText());
if(MONTO >= 300){
DESCUENTO = MONTO * 0.25;
jLabel5.setText("DESCUENTO 25%");
jTxt_Desct.setText(String.valueOf(DESCUENTO));
}else{
if( (MONTO > 150) && (MONTO < 300)){
DESCUENTO = MONTO * 0.2;
jLabel5.setText("DESCUENTO 20%");
jTxt_Desct.setText(String.valueOf(DESCUENTO));
}else{
DESCUENTO = 0;
jLabel5.setText("NO HAY DESCUENTOS");
jTxt_Desct.setText("0");
}
}
}
Imports System.Console
Module calcula_desct
Dim Monto, Descuento As Decimal
Sub Main()
WriteLine("10. GENERAR UN DESCUENTO SEGÚN MONTO DE COMPRA.")
WriteLine("")
Write("Ingrese Monto : ")
Monto = ReadLine()
WriteLine("")
If (Monto >= 300) Then
Descuento = Monto * 0.25
WriteLine("El Descuento es 25% : " & Descuento)
Else
If ((Monto > 150) And (Monto < 300)) Then
Descuento = Monto * 0.2
WriteLine("El Descuento es 20% : " & Descuento)
Else
WriteLine("No Hay Descuento")
End If
End If
ReadLine()
End Sub
End Module
Private Sub Btn_Calcular_Click(sender As Object, e As EventArgs) Handles Btn_Calcular.Click
Dim Monto, Descuento As Decimal
Monto = Txt_Monto.Text
If (Monto >= 300) Then
Descuento = Monto * 0.25
Lbl_msg.Text = "El Descuento es 25% : " & Descuento
Else
If ((Monto > 150) And (Monto < 300)) Then
Descuento = Monto * 0.2
Lbl_msg.Text = "El Descuento es 20% : " & Descuento
Else
Lbl_msg.Text = "No Hay Descuento"
End If
End If
End Sub
Sub Descuento()
Dim Monto, Descuento As Double
Monto = CInt(Range("C12").Value)
If (Monto > 300) Then
Descuento = Monto * 0.25
Range("G11").Value = "EL DESCUENTO ES 25% "
Range("G12").Value = Descuento
Else
If (Monto > 150) And (Monto < 300) Then
Descuento = Monto * 0.2
Range("G11").Value = "EL DESCUENTO ES 20% "
Range("G12").Value = Descuento
Else
Range("G11").Value = "EL DESCUENTO ES 0% "
Range("G12").Value = 0
End If
End If
End Sub
Sub Descuento2()
Dim Monto, Descuento As Double
Monto = CInt(InputBox("INGRESE MONTO "))
If (Monto > 300) Then
Descuento = Monto * 0.25
MsgBox "EL DESCUENTO DE 25% ES : " & Descuento
Else
If (Monto > 150) And (Monto < 300) Then
Descuento = Monto * 0.2
MsgBox "EL DESCUENTO DE 20% ES : " & Descuento
Else
MsgBox "EL DESCUENTO ES : " & 0 & "%"
End If
End If
End Sub
Private Sub btn_calcular_Click()
Dim Monto, Descuento As Double
Monto = CDbl(txt_num.Text)
If (Monto > 300) Then
Descuento = Monto * 0.25
Label5.Caption = "DESCUENTO ES 25%"
txt_Desc.Text = Descuento
Else
If (Monto > 150) And (Monto < 300) Then
Label5.Caption = "DESCUENTO ES 20%"
Descuento = Monto * 0.2
txt_Desc.Text = Descuento
Else
txt_Desc.Text = 0 & "%"
End If
End If
End Sub