All pastes #802595 Raw Edit

DArk3Lite

public text v1 · immutable
#802595 ·published 2007-11-30 13:13 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;
     FILE * in= fopen("rooms.txt", "r");
     FILE * out= fopen("rooms.txt", "w");
     
     if (in == NULL)
     { 
            printf("File cannot be found");
            return 1;
            }
     else
     {
          printf("File opened successfully.\n");
          }
     fprintf(out, "RoomNumber      RoomArea         CostToCarpetRoom\n\n");
     fscanf(in, "%d %lf %lf %lf", &room_number, &lenght, &breadth, &cost);  
          while(room_number!=0) {
               area= lenght * breadth;
               totalcost= totalcost + cost; 
               rooms = room_number++;
               }
               
                        
     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" );        
     if (out == NULL)
     { 
            printf("File cannot be found or created");
            exit(1);
            }
            
     printf("\n\nNow closing file...\n");
    fclose(in);
    fclose(out);
    return 0;
  
}