For starters there is neither declaration of the function welcome
that is called in main
welcome();
Within the function wednesday
you need to check whether this call of scanf
scanf("%d", &discount);
was successful. To make the function correct you should at least initially initialize the variable discount for example like
int discount = 2;
In this case if the call of scanf
will not be successful the function will return the value 2
by default.
Within the function cost
there are used two uninitialized variables price
and discount
void cost(int wednesday){
int price;
int discount;
if(discount == 1){
price = price - 2;
}
else{
price = price;
}
}
So the function invokes undefined behavior.
Moreover the parameter wednesday
is not used.
You should declare the function with one more parameter that specifies the price. And the result price should be returned from the function to main
. For example
int cost( int price, int discount ){
if(discount == 1 && price > 2 ){
price = price - 2;
}
return price;
}
Also the variable price should have at least unsigned integer type or maybe a float type.
unsigned int cost( unsigned int price, int discount ){
if(discount == 1 && price > 2 ){
price = price - 2;
}
return price;
}
Pay attention to that according to the C Standard the function main without parameters shall be declared like
int main( void )