1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include<stdio.h>
void getUserInput(int *numHospitalRooms, int *numFlowers);
int main()
{
float hospitalRoomsPrices_Array[5]={300.00,350.00,400.00,450.00,500.00};
int numHospitalRooms = 0;
int numFlowers = 0;
float flowerPricing = 2.50;
getUserInput(numHospitalRooms, numFlowers);
float flowerCost = numFlowers*flowerPricing;
float totalCost = (flowerCost + hospitalRoomsPrices_Array[numHospitalRooms]);
//
printf("\nCost for %d room(s): $%.2f", numHospitalRooms, hospitalRoomsPrices_Array[numHospitalRooms]);
printf("\nFlower(s) Cost: $%.2f \n", flowerCost);
printf("\nTotal cost: $%.2f", totalCost);
return 0;
}
void getUserInput(int *numHospitalRooms, int *numFlowers)
{
do {
printf("\nHow many hospital rooms: ");
scanf("%d", &numHospitalRooms);
if (numHospitalRooms < 1 || numHospitalRooms > 5)
{
printf("\nInvalid number of rooms, room number must be between 1-5!\n");
}
}while((numHospitalRooms < 1 || numHospitalRooms > 5));
do {
printf("\nEnter number of flowers: ");
scanf("%d", &numFlowers);
if (numFlowers < 0)
{
printf("\nInvalid number of flowers, negative values are not accepted!\n");
}
}while((numFlowers < 0));
}
|