the following short program asks user to enter # of hospital rooms (between 1-5), and asks for number of flowers, which cannot be a negative number.
Then, it picks based on how many rooms the price from the hospitalRoomsPrices_Array[5]
, and it also displays the total flowers multiplied by $2.50 each.
finally, total cost of room(s) price + flower costs is added
heres the code:
#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));
}
i am getting a lot of warnings when i compile:
-
[Warning] passing argument 1 of 'getUserInput' makes pointer from
integer without a cast[Note] expected 'int *' but argument is of type 'int'
[Warning] passing argument 2 of 'getUserInput' makes pointer from
integer without a cast[Warning] comparison between pointer and integer
not only that, but entering a negative number isnt being taken into account at all in the getUserInput()
conditional statements.
here is an example of the output:
How many hospital rooms: 6
Invalid number of rooms, room number must be between 1-5!
How many hospital rooms: -1
Invalid number of rooms, room number must be between 1-5!
How many hospital rooms: 5
Enter number of flowers: -1
Cost for 0 room(s): $300.00 Flower(s) Cost: $0.00
Total cost: $300.00
what am i missing? why are the warnings coming up like that and messing with the program?