Advanced · C PROGRAMMING

Repair estimate mini project

What you will learn

Combine functions, structures and arrays in a small repair estimate.

Understand the concept

Each line item stores a name, quantity and unit price in paise. Integer paise avoids binary floating-point rounding for this small example. A function totals the array, and the program prints rupees and paise separately. Real billing also needs checked arithmetic and explicit tax and rounding rules.

Read the example

The complete program appears below. Read it first, predict the output, then run it.

Expected output

Estimate: INR 751.00

Practise

Print each line item before the total. Add a third item and verify the total by hand.

Common mistake

Validate quantities and prices before calculating. Large integer products can overflow; this educational example uses bounded constants.

Lesson discussion

Log in to participate.

#include <stdio.h>
struct Item { const char *name; int quantity; long unit_paise; };
long estimate(const struct Item *items, size_t count) {
    long total = 0;
    for (size_t i = 0; i < count; ++i) total += items[i].quantity * items[i].unit_paise;
    return total;
}

int main(void) {
    struct Item items[] = {{"Service", 1, 50000}, {"Part", 2, 12550}};
    long total = estimate(items, sizeof items / sizeof items[0]);
    printf("Estimate: INR %ld.%02ld\n", total / 100, total % 100);
    return 0;
}
PRACTICE LAB

Read. Edit. Run.

C source · .c

Experiment with the program below. Your code and input are sent to the selected compiler only when you run it.

Tab indents · Shift+Tab unindents · Esc then Tab leaves the editor · Ctrl/Cmd+Enter runs · Ctrl/Cmd+S saves a draft

Changes save automatically to your account.

Input / output example

Example input
No input required.
Expected output for the original program
Estimate: INR 751.00
Output will appear here.

Log in to save your progress

Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA