Question

C Programming I have this cost estimation program, but I want to add to it more...

C Programming

I have this cost estimation program, but I want to add to it more functions to be more accurate and more useful. I want to add to the program an array and a loop that can help me with the materials that can be use to the building, as ceramic, wood and concrete and extra functions.

##########

#include <stdio.h>
int main(void)
{
float wid,len,yrs;
int metersq = 2000;
int floors,rooms,win,doors,restrooms,umet;
char floortype[20];
char ti[20];
int woodfloor = 25;
int ceramic = 15;
int doorcost = 200 , metaldoor = 150;
int windowcost = 100;
int materialcost = 131.0371;
int paintcost = 100;
int arcitectcost = 3000;
int restroomcost = 2000;
int costengineer = 6000;
int costeachworker = 4000;
int totalrooms ,totalcost, totalwin , totalmaterial,totalmaterialcost,totalarchitect, totaldoors ,totalarchitectcost, totalrestroom , totalcostrest , totalcostworker , totalcostfloor, totalwincost, totalnoengineer, totalengineercost;
printf("How long is your width and length of your building?\n");
scanf("%f %f",&wid,&len);
printf("How many floors will the building will have?\n");
scanf("%d",&floors);
printf("How many rooms per floor?\n");
scanf("%d",&rooms);
printf("How many windows per floor?\n");
scanf("%d",&win);
printf("How many doors per floor?");
scanf("%d",&doors);
printf("How many years would you like to wait for the project? \n");
scanf("%f",&yrs);
printf("Which floor material would you like to use on your biulding? (wood, ceramic or concrete)\n");
scanf("%s",floortype);//read a string using %s itself , no & is required to read a string
printf("How soon do you want your building? normal time or faster? Enter normaltime or faster \n");
scanf("%s",ti);//read a string using %s itself , no & is required to read a string
printf("How many restrooms per floor?\n");
scanf("%d",&restrooms);

totalrooms = floors*rooms;
totalwin = floors*win;
totaldoors = doors + totalrooms;
totalrestroom = floors*restrooms;
totalcostrest = totalrestroom*restroomcost;
totalcostworker = yrs*costeachworker;
if(ti == "normaltime")
{
totalcostworker = totalcostworker*1;
}
else
{
totalcostworker = 2*totalcostworker;
}
if(floortype == "wood")
{
totalcostfloor = 25*floors;
}
else
{
totalcostfloor = 15*floors;
}
totalwincost = totalwin*windowcost;
  
totalnoengineer = floors*2;
totalengineercost = totalnoengineer *costengineer;
  
totalarchitect = floors*1;
totalarchitectcost = totalarchitect*arcitectcost;
totalmaterial = wid*len*floors;
totalmaterialcost = totalmaterial*materialcost;
totalcost = totalmaterialcost+totalarchitectcost+ totalwincost+ totalcostfloor+totalcostworker+totalcost;
printf("the total cost is %d dollars",totalcost);
return 0;
}


0 0
Add a comment Improve this question Transcribed image text
Answer #1

strings can't be compared directly so use strcmp method from header file string.h

code

#include <stdio.h>
#include <string.h>

int main(void)
{
//for taking more than one building value
char choice;
do{
float wid,len,yrs;
int metersq = 2000;
int floors,rooms,win,doors,restrooms,umet;
char floortype[20];
char ti[20];

//chars for comparison
char *w="wood",*normaltime = "normaltime";
int woodfloor = 25;
int ceramic = 15;
int doorcost = 200 , metaldoor = 150;
int windowcost = 100;
float materialcost = 131.0371;
int paintcost = 100;
int arcitectcost = 3000;
int restroomcost = 2000;
int costengineer = 6000;
int costeachworker = 4000;
int totalrooms ,totalcost, totalwin , totalmaterial,totalmaterialcost,totalarchitect, totaldoors ,totalarchitectcost, totalrestroom , totalcostrest , totalcostworker , totalcostfloor, totalwincost, totalnoengineer, totalengineercost;
printf("How long is your width and length of your building?\n");
scanf("%f %f",&wid,&len);
printf("How many floors will the building will have?\n");
scanf("%d",&floors);
printf("How many rooms per floor?\n");
scanf("%d",&rooms);
printf("How many windows per floor?\n");
scanf("%d",&win);
printf("How many doors per floor?");
scanf("%d",&doors);
printf("How many years would you like to wait for the project? \n");
scanf("%f",&yrs);
printf("Which floor material would you like to use on your biulding? (wood, ceramic or concrete)\n");
scanf("%s",floortype);//read a string using %s itself , no & is required to read a string
printf("How soon do you want your building? normal time or faster? Enter normaltime or faster \n");
scanf("%s",ti);//read a string using %s itself , no & is required to read a string
printf("How many restrooms per floor?\n");
scanf("%d",&restrooms);

totalrooms = floors*rooms;
totalwin = floors*win;
totaldoors = doors + totalrooms;
totalrestroom = floors*restrooms;
totalcostrest = totalrestroom*restroomcost;
totalcostworker = yrs*costeachworker;
if(strcmp(ti,normaltime)==0)
{
totalcostworker = totalcostworker*1;
}
else
{
totalcostworker = 2*totalcostworker;
}
if(strcmp(floortype,w)==0)
{
totalcostfloor = 25*floors;
}
else
{
totalcostfloor = 15*floors;
}
totalwincost = totalwin*windowcost;
  
totalnoengineer = floors*2;
totalengineercost = totalnoengineer *costengineer;
  
totalarchitect = floors*1;
totalarchitectcost = totalarchitect*arcitectcost;
totalmaterial = wid*len*floors;
totalmaterialcost = totalmaterial*materialcost;
totalcost = totalmaterialcost+totalarchitectcost+ totalwincost+ totalcostfloor+totalcostworker+totalcost;
printf("the total cost is %d dollars",totalcost);
printf("enter q to quit");

//space to read character otherwise it reads blank space
scanf("%c",&choice);
}while(choice!='q');
return 0;
}

output

How long is your width and length of your building? How many floors will the building will have? How many rooms per floor? Ho

Add a comment
Know the answer?
Add Answer to:
C Programming I have this cost estimation program, but I want to add to it more...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string usi...

    C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string using the RSA algorithm (C90 language only). It can contain ONLY the following libraries: stdio, stdlib, math and string. I want to use the following function prototypes to try and implement things: /*Check whether a given number is prime or not*/ int checkPrime(int n) /*to find gcd*/ int gcd(int a, int h) void Encrypt(); void Decrypt(); int getPublicKeys(); int getPrivateKeys();...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

  • Do you have a flowgorithim flow chart for this code? #include <stdio.h> int main() { int num,i=0,sum=0; float aver...

    Do you have a flowgorithim flow chart for this code? #include <stdio.h> int main() { int num,i=0,sum=0; float average; int customerNumbers[num]; int customerSales[num]; printf("How many customers do you want to track?\n"); scanf("%d",&num); while(i<num) { printf("Enter the customer number. "); scanf("%d",&customerNumbers[i]); printf("Enter the sales for the customer "); scanf("%d",&customerSales[i]); i++; } printf("Sales for the Customer"); printf("\nCustomer Customer"); printf("\nNumber Sales"); for(i=0;i<num;i++) { printf("\n %d \t %d",customerNumbers[i], customerSales[i]); sum=sum+customerSales[i]; } average=(int)sum/num; printf("\n Total sales are $%d",sum); printf("\n Average sales are $%.2f",average); printf("\n --------------------------------------------");...

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • Create a UNIX makefile for the following C program: //convert.c char toUpper(char c){ if(c>='a' && c<='z')...

    Create a UNIX makefile for the following C program: //convert.c char toUpper(char c){ if(c>='a' && c<='z') return c-32; return c; } //converting sentance to upper void convertSentence(char *sentence){ int i=0; while(sentence[i]!='\0'){ //convert to upper for each character sentence[i] = toUpper(sentence[i]); i++; } } //converting all sentences into uppercase void convertAll(char **sentenceList, int numOfSentences){ int i=0; while(i<numOfSentences){ //calling convertsentence function to conver uppercase convertSentence(sentenceList[i]); i++; } } sentences.c #include<stdio.h> #include<stdlib.h> #include "convert.c" int main(){ //declaring character array char **mySentences; int noOfSentences;...

  • C Programming Question Hi, I have the following code and in my submission I'm supposed to...

    C Programming Question Hi, I have the following code and in my submission I'm supposed to only include function definitions (i.e. implementations) in the file. However, I'm not NOT required to write the main, struct definitions and function prototypes. Could someone help me fix this code? Text Version: #include<stdio.h> #include<stdlib.h> #include <string.h> struct ip_address { int octet_1; int octet_2; int octet_3; int octet_4; }; typedef struct ip_address ip_address_t; void print_ip_address(ip_address_t ip1){ printf("%d.%d.%d.%d", ip1.octet_1,ip1.octet_2,ip1.octet_3,ip1.octet_4); } int is_valid(ip_address_t ip1){ if(ip1.octet_1 < 0...

  • I have this C program that calculates an input and converts it to a BMI calculation....

    I have this C program that calculates an input and converts it to a BMI calculation. Any idea how this would look as an LC3 program? I'm taking an LC3 programming class next semester and want an idea of what this code would even translate to, just trying to get a head start. I'm more so curious on how to get user input in a LC3 program, then I can try myself and figure it out from there. int main()...

  • Using C, I need help debugging this program. I have a few error messages that I'm...

    Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT