How do I use the correct syntax with a character data type to compute? - TechRepublic
Question
September 23, 2010 at 11:50 AM
programmer82

How do I use the correct syntax with a character data type to compute?

by programmer82 . Updated 15 years, 9 months ago

I am having some issues with this code. Basically, I am not using the char data type in the correct way. Can someone please show me what I am doing wrong?

I need the user to enter Mohogany to compute the formula or Oak to compute the next formula then output the correct data given from the users input. Thanks in advance! Here is the code below.

#include
#include
#include

int main(void)
{
int deskWidth=0;
int deskHeight=0;
int numDrawers=0;
int price=200;
char woodType[8];

printf(“Please enter the width of the desk you would like to order:\n”);
scanf(“%d”, &deskWidth);

printf(“Please enter the height of the desk you would like to order:\n”);
scanf(“%d”, &deskHeight);

printf(“Please enter the number of drawers you would like your desk to have:\n”);
scanf(“%d”, &numDrawers);

printf(“Declare your wood type. Enter Mahogany or Oak:\n”);
scanf(“%c”, &woodType);

if(deskWidth * deskHeight>750)
{
price=price+50;
}
if(woodType==”Mahogany”)
{
price=price+150;

else if(woodType==”Oak”)
{
price=price+125;
}
}

price=price+numDrawers*30;

printf(“The desk length you requested is:%d\n”, deskHeight);
printf(“The desk width you requsted is:%d\n”, deskWidth);
printf(“The wood type you requested is:%d\n”, woodType);
printf(“The number of drawers you requested is:%d\n”, numDrawers);
printf(“The total price of your desk is:%d\n”, price);

system(“Pause”);
return 0;
}

This discussion is locked

All Comments