Question

Locked

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

By programmer82 ·
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<stdio.h>
#include<stdlib.h>
#include<ctype.h>

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 conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Two things off the top of my head

by Tony Hopkinson In reply to How do I use the correct ...

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

should be

printf("Declare your wood type. Enter Mahogany or Oak:\n");
scanf("%7s", &woodType);

seven chars to go in char[ leaving a null to terminate


and

printf("The wood type you requested is:%d\n", woodType);

should be

printf("The wood type you requested is:%s\n", woodType);

woodtype not being a number...

If you are wondering why the compiler didn't point these typing errors out , well that's the horror and the glory of C...

Back to Windows Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums