I need help to solve this problem, please


Joined
Nov 7, 2022
Messages
2
Reaction score
1
Create a function:
float unit_price(const float pack_price, const int rolls_count, const int pieces_count) with three parameters:

const float pack_price - Pack price
const int rolls_count - Number of rolls
const const pieces_count - Number of pieces in a roll
For the given parameters, the function calculates what the unit price is for 100 pieces of scraps. The function returns a value with the result rounded to 2 decimal places.
 
Ad

Advertisements

Ad

Advertisements

Joined
Nov 7, 2022
Messages
2
Reaction score
1
what have you tried?
Solved , but thanks :))

float unit_price(const float pack_price, const int rolls_count, const int pieces_count){
int rolls_pieces = rolls_count * pieces_count;
float price_hundred = (pack_price / (float)rolls_pieces) * 100;
float round_price = roundf(price_hundred * 100) / 100;
return round_price;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top