#include <stdio.h>
void function1(void);

void main ()

    function1();
}

void function1(void)
{
    int a;
    int b;
    int c;
    int d;
    int i=0;
    int rooms;

    printf("enter number of rooms\n");
    scanf("%d",&rooms);

    do
    {
    printf("Enter the price per meter of the tiles\n");
    scanf("%d",&a);

    printf("Enter the length\n");
    scanf("%d",&b);

    printf("Enter the breath\n");
    scanf("%d",&c);

    printf("Enter the grout type\ninferior qualtiy= 5$ /metre sq\nsuperior qualtiy= 7$ /metre sq\n");
    scanf("%d",&d);

    printf("Total area %d\n",b*c);
    printf("Tile costings of room %d\n",a*b*c*d);
    scanf("%c");
    i++;
}
    while(i!=rooms);
}

I have got this program that helps a tile layer to calculate the pricing of each room of a house and I am currently stuck on how to make the grand total of the rooms, each room has its own total and I require help to have the grand total price of the rooms =/

Recommended Answers

All 3 Replies

To find the grand total, have a sum outside of the loop, and add every total to the sum every iteration. Ie:

...
int sum = 0;
do {
    ...
    sum += a*b*c*d;
} while (i != rooms)

Some other things wrong with your code:
1. main always returns int. Change void main() to int main(), otherwise your code is incorrect and will not compile on a mordern c compiler.
2. Your missing a { at the beginning of main.
3. function1, a, b, c and d can all have more meaningful names.

yes thats what I need but I don't know how I can make it =/ I don't know how to name the answers generated from the loop cause if I do that I can automatically issue a grand total

I pretty much gave you the code for it - what you you mean you don't know how to do it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.