All pastes #802943 Raw Edit

Untitled

public text v1 · immutable
#802943 ·published 2007-11-30 19:39 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main ()

{
        int rooms, room_number;
        double area, cost, totalcost, lenght, breadth;
        char hotel;
        /****************************/
        double largest_area;
        int largest_room;
        /****************************/
        rooms=0;
        FILE * in= fopen("rooms1.txt", "r");
        FILE * out= fopen("rooms.txt", "w");

        if (in == NULL)
        {
                printf("File cannot be found");
                return 1;
        }
        else
        {
                printf("File opened successfully.\n");
        }
        if (out == NULL)
        {
                printf("File cannot be found or created");
                exit(1);
        }

        largest_room=0;
        largest_area=0.0;

        fprintf(out, "RoomNumber      RoomArea         CostToCarpetRoom\n\n");
        while(room_number!=0) 
        {
                fscanf(in, "%d %lf %lf %lf", &room_number, &lenght, &breadth, &cost);
                if(room_number == 0)
                        break;
                area= lenght * breadth;
                if(area>largest_area)
                {
                        largest_room = room_number;
                        largest_area = area;
                }

                fprintf(out, "%d, %lf, %lf\n", room_number, area, cost);
                totalcost= totalcost + cost;
                rooms = rooms++;
        }


        fprintf(out, "%d rooms were processed\n\n", rooms);
        fprintf(out, "Total cost of carpeting all the rooms are %lf\n\n", totalcost);
        fprintf(out, "Room %d will cost the most to carpet\n\n" );
        fprintf(out, "Room %d is the largest with an area of %lf\n", largest_room, largest_area );


        printf("\n\nNow closing file...\n");
        fclose(in);
        fclose(out);
        return 0;

}