after much thinking, i finally figured it out:
#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 - 1]);
printf("\nCost for %d room(s): $%.2f", numHospitalRooms, hospitalRoomsPrices_Array[numHospitalRooms - 1]);
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));
}
this should be like this: getUserInput(&numHospitalRooms, &numFlowers);
and this should be like this:
scanf("%d", numHospitalRooms); //no appresand
There was no need for all that back and forth for such a simple mistake anyone could have pointed out from here. As a student trying to learn, this feels very discouraging to have to fight for learning my mistakes. a simple two lines of code recommendation like i posted now would have shined a bright day here instead of a negative atmosphere.
solved pointers not pointing correctly and comparison warnings