0% found this document useful (0 votes)
13 views

Programa C++

This document contains a C++ program for calculating train ticket prices. It defines constants for the maximum distance and days, kilometer price, and discount percentage. It includes functions to validate numeric user input and calculate the ticket price based on distance, days, and any applicable discounts. The main function prompts the user to enter distance and days, validates the input, calls the price calculation function, and prints a thank you message.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Programa C++

This document contains a C++ program for calculating train ticket prices. It defines constants for the maximum distance and days, kilometer price, and discount percentage. It includes functions to validate numeric user input and calculate the ticket price based on distance, days, and any applicable discounts. The main function prompts the user to enter distance and days, validates the input, calls the price calculation function, and prints a thank you message.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

// boleto de ferrocarril.cpp : Este archivo contiene la función "main".

La ejecución del
programa comienza y termina ahí.

// Autor Santafé Rueda Christian Abelardo

#include <cstdlib>

#include <iostream>

#include <ctype.h>

using namespace std;

const double DAYMAX = 7,


// declaro constantes

KM = 800,

DESC = 0.3,

PVP_KM = 2.50;

int VALIDANUM(char NUM[50])


// Validacion de ingreso numeros

int i = 0, j = 0, k;

k = strlen(NUM);

while (i < k && j == 0)

isdigit(NUM[i]) != 0 ? i++ : j = 1;

return j;

void CALCULARPRECIO(int dist, int days)


//Calcula el precio tomando en cuenta los parametros del descuento

double TIME, TOT, desc;

if (dist <= KM && days <= DAYMAX)

TIME = dist * PVP_KM;


cout << " ===== Costo del billete ===== " << TIME << endl;

if (dist > KM && days <= DAYMAX)

TIME = dist * PVP_KM;

cout << " ===== Costo del billete ===== " << TIME << endl;

if (dist <= KM && days > DAYMAX)

TIME = dist * PVP_KM;

cout << " ===== Costo del billete ===== " << TIME << endl;

if (dist > KM && days > DAYMAX)

TIME = dist * PVP_KM;

cout << " ===== Costo del billete ===== " << TIME << endl;

desc = TIME * DESC;

cout << " ====== Descuento ===== " << desc << endl;

TOT = (TIME - desc);

cout << " ===== El total del boleto es ===== " << TOT << endl;

int main()

char NUM[50];

int DIST, DAYS, CONT;

do

cout << " ===== Introducir distancia (Km) ===== \n";

cin >> NUM;


CONT = VALIDANUM(NUM);

(CONT == 0) ? DIST = atoi(NUM) : CONT=1;

} while (CONT == 1);

do

cout << " ===== Introducir dias de estancia ===== \n";

cin >> NUM;

CONT = VALIDANUM(NUM);

(CONT == 0) ? DAYS = atoi(NUM) : CONT = 1;

} while (CONT == 1);

CALCULARPRECIO(DIST, DAYS);

cout << "\n\n\n";

cout << " =================== GRACIAS ================== " << endl;

You might also like