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 / 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 |
Is it possible to execute code even after the program exits the main() function?
What is the proper way of these job Tell me about there full work
EXPLAIN #INCLUDE<STDIO.H> EXPLAIN #INCLUDE<CONIO.H>
What is hash table in c?
what is event driven software and what is procedural driven software?
Explain what math functions are available for integers? For floating point?
Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
List some of the static data structures in C?
What is structure data type in c?
how to find the sizof of any datatype using bit manipulations
Program to find larger of the two numbers without using if-else,while,for,switch
Design a program using an array that searches a number if it is found on the list of the given input numbers and locate its exact location in the list.