Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Develop a program that computes the new price of an item.
The program should receive a
character variable colour and a double precision
floating-point variable price from the
user. Discount rate is determined based on the colour of the
discount sticker, as shown in the
following table. An error message should be printed if an
invalid colour has been entered

Answer Posted / tw

I'm still learning, but I made this. The color input isn't
validated for random strings characters (will get a seg
fault). Still need to add the calculations

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


void colors() {

int ctr = 0;
double price;
char color[20], tmp[20];
char colorMenu[9][20] = {" ", "WHITE", "BLACK", "RED",
"GREEN", "BLUE", "ORANGE", "YELLOW", "PURPLE"};
int discount[9]= { 0, 15, 20, 25, 30, 35, 40, 45, 50 };

do {
printf("\n\nEnter the discount sticker color -> ");
fgets(tmp, 20, stdin);
sscanf(tmp, "%s", &color);
} while (isalpha(color[1]) == 0);

do {
printf("\n\nEnter the price -> ");
fgets(tmp, 20, stdin);
} while (sscanf(tmp, "%f", &price) == 0);

for (int x = 0; color[x] != '\0'; x++)
color[x] = toupper(color[x]);

for (ctr = 0; (strcmp(color, colorMenu[ctr]) != 0); ctr++);

printf("\nPICK: %d", ctr);
printf("\nYOU CHOSE: %s, DISCOUNT: %d percent off",
colorMenu[ctr], discount[ctr]);

}

int main() {

colors();

return (0);
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe static function with its usage?

1268


Can a pointer be volatile in c?

1041


Why is it important to memset a variable, immediately after allocating memory to it ?

2131


What is the time and space complexities of merge sort and when is it preferred over quick sort?

1133


Place the #include statement must be written in the program?

1086


What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

2040


What is the difference between pure virtual function and virtual function?

1179


What's the difference between constant char *p and char * constant p?

1191


What does != Mean in c?

1092


What are integer variable, floating-point variable and character variable?

1297


The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this

3656


Is it better to use a macro or a function?

1204


a character or group of characters that defines a register,or a part of storage a) memory b) byte c) address d) linear list

1044


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

1176


What are pointers really good for, anyway?

1117