``````#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 =/
``````
2
Contributors
3
Replies
17
Views
4 Years
Discussion Span
Last Post by Hiroshe

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.