#include <stdio.h>
#include string.h
#define C17_PRICE 12.80
#define F25_PRICE 4.29
#define DN3_PRICE 10.00
#define GG7_PRICE 35.00
#define MV4_PRICE 18.49
#define DISCOUNT 0.05
#define DISC_THRES 10
#define SAME_DAY_DELIVERY = 35.0
#define NEXT_DAY_DELIVERY = 20.0
typedef enum{ WRONG, C17, F25, DN3, GG7, MV4} part
/*--- Function Prototypes ------------*/
part getPartType ( void );
int getquantity ( void );
int getDeliveryOption ( void );
float calcPriceOfParts( part orderedPart, int quantity );
float calcTotalCarges ( float orderPrice, char deliveryFee );
int main ( void )
{
float totalCharges, priceOfParts, deliveryFee;
int quantity, deliveryOption;
part partType;
partType = getPartType();
if ( partType != WRONG )
{
quantity = getQuantity();
if ( quantity != -1 )
{
priceOfParts = calcPriceOfParts(
partType, quantity );
deliveryOption =
getDeliveryOption();
switch(deliveryOption)
{
case 1 :
deliveryFee = SAME_DAY_DELIVERY;
break;
case 2 : deliveryFee = NEXT_DAY_DELIVERY;
break;
default: printf("The order has been
canceled\n");
return
-1;
}
printf ("Total
charges: $%.2f\n", calcTotalCarges (priceOfParts,
deliveryFee));
}
}
else
printf("Wrong part type\n");
return 0;
}
/*=== Function Definitions ===*/
part getPartType ( void )
{
char partName[4];
part partNumber;
printf ("Enter the part type (C17, F25, DN3, GG7 or
MV4): ");
if( scanf ("%s", &partName) == 1)
{
if (strcmp (partName, "C17") == 0) partNumber =
C17;
else if (strcmp (partName, "F25") == 0) partNumber =
F25;
else if (strcmp (partName, "DN3") == 0) partNumber =
DN3;
else if (strcmp (partName, "GG7") == 0) partNumber =
GG7;
else if (strcmp (partName, "MV4") == 0) partNumber =
MV4;
else partNumber = WRONG;
}
else
partNumber = WRONG;
return partNumber;
}
int getQuantity ( void )
{
int quantity = 0;
printf ("Enter the quantity: ");
if( scanf ("%d", &quantity)==1 )
{
if (quantity <= 0)
quantity = -1;
}
else
quantity = -1;
return quantity;
}
int getDeliveryOption ( void )
{
int deliveryOption;
printf ("Select a delivery option(1 - same day, 2 -
next day, or 3 - cancel the order): ");
if( scanf ("%d", &deliveryOption) == 1)
{
if( deliveryOption==1 || deliveryOption==2 )
return deliveryOption;
else
return -1;
}
else
return -1;
}
float calcPriceOfParts( part orderedPart, int quantity )
{
float itemPrice, price, discount = 0.0;
switch( orderedPart )
{
case C17: itemPrice = C17_PRICE;
break;
case F25: itemPrice = F25_PRICE;
break;
case DN3: itemPrice =
DN3_PRICE;
break;
case GG7: itemPrice =
GG7_PRICE;
break;
case MV4: itemPrice =
MV4_PRICE;
break;
default: itemPrice = -1.0;
}
price = itemPrice * quantity;
if( quantity > DISC_THRES )
price -= DISCOUNT * itemPrice * ( quantity -
DISC_THRES );
return price;
}
float calcTotalCarges ( float orderPrice, char deliveryFee )
{
return orderPrice + deliveryFee;
}
This is my C code I don't know what is the error it does not run can you fix it or debug it for me
please find the updated running code:
#include <stdio.h>
#include <string.h>
#define C17_PRICE 12.80
#define F25_PRICE 4.29
#define DN3_PRICE 10.00
#define GG7_PRICE 35.00
#define MV4_PRICE 18.49
#define DISCOUNT 0.05
#define DISC_THRES 10
#define SAME_DAY_DELIVERY 35.0
#define NEXT_DAY_DELIVERY 20.0
enum part{ WRONG, C17, F25, DN3, GG7, MV4};
/*--- Function Prototypes ------------*/
int getquantity ( void );
int getDeliveryOption ( void );
enum part getPartType (void);
float calcPriceOfParts( enum part orderedPart, int quantity
);
float calcTotalCarges ( float orderPrice, char deliveryFee );
int main ( void )
{
float totalCharges, priceOfParts, deliveryFee;
int quantity, deliveryOption;
enum part partType;
partType = getPartType();
if ( partType != WRONG )
{
quantity = getQuantity();
if ( quantity != -1 )
{
priceOfParts = calcPriceOfParts( partType, quantity );
deliveryOption = getDeliveryOption();
switch(deliveryOption)
{
case 1 : deliveryFee = SAME_DAY_DELIVERY;
break;
case 2 : deliveryFee = NEXT_DAY_DELIVERY;
break;
default: printf("The order has been canceled\n");
return -1;
}
printf ("Total charges: $%.2f\n", calcTotalCarges (priceOfParts,
deliveryFee));
}
}
else
printf("Wrong part type\n");
return 0;
}
/*=== Function Definitions ===*/
enum part getPartType (void)
{
char partName[4];
enum part partNumber;
printf ("Enter the part type (C17, F25, DN3, GG7 or MV4): ");
if( scanf ("%s", &partName) == 1)
{
if (strcmp (partName, "C17") == 0) partNumber = C17;
else if (strcmp (partName, "F25") == 0) partNumber = F25;
else if (strcmp (partName, "DN3") == 0) partNumber = DN3;
else if (strcmp (partName, "GG7") == 0) partNumber = GG7;
else if (strcmp (partName, "MV4") == 0) partNumber = MV4;
else partNumber = WRONG;
}
else
partNumber = WRONG;
return partNumber;
}
int getQuantity ( void )
{
int quantity = 0;
printf ("Enter the quantity: ");
if( scanf ("%d", &quantity)==1 )
{
if (quantity <= 0)
quantity = -1;
}
else
quantity = -1;
return quantity;
}
int getDeliveryOption ( void )
{
int deliveryOption;
printf ("Select a delivery option(1 - same day, 2 - next day, or 3
- cancel the order): ");
if( scanf ("%d", &deliveryOption) == 1)
{
if( deliveryOption==1 || deliveryOption==2 )
return deliveryOption;
else
return -1;
}
else
return -1;
}
float calcPriceOfParts( enum part orderedPart, int quantity
)
{
float itemPrice, price, discount = 0.0;
switch( orderedPart )
{
case C17: itemPrice = C17_PRICE;
break;
case F25: itemPrice = F25_PRICE;
break;
case DN3: itemPrice = DN3_PRICE;
break;
case GG7: itemPrice = GG7_PRICE;
break;
case MV4: itemPrice = MV4_PRICE;
break;
default: itemPrice = -1.0;
}
price = itemPrice * quantity;
if( quantity > DISC_THRES )
price -= DISCOUNT * itemPrice * ( quantity - DISC_THRES );
return price;
}
float calcTotalCarges ( float orderPrice, char deliveryFee )
{
return orderPrice + deliveryFee;
}
#include <stdio.h> #include string.h #define C17_PRICE 12.80 #define F25_PRICE 4.29 #define DN3_PRICE 10.00 #define GG7_PRICE...
Finish function to complete code. #include <stdio.h> #include <stdlib.h> #include<string.h> #define Max_Size 20 void push(char S[], int *p_top, char value); char pop(char S[], int *p_top); void printCurrentStack(char S[], int *p_top); int validation(char infix[], char S[], int *p_top); char *infix2postfix(char infix[], char postfix[], char S[], int *p_top); int precedence(char symbol); int main() { // int choice; int top1=0; //top for S1 stack int top2=0; //top for S2 stack int *p_top1=&top1; int *p_top2=&top2; char infix[]="(2+3)*(4-3)"; //Stores infix string int n=strlen(infix); //length of...
#include <stdio.h> #include <string.h> #define WORDLEN 20 char smallest_word[WORDLEN + 1], largest_word[WORDLEN + 1], word[WORDLEN + 1]; void get_first_word(void); void get_another_word(void); void get_word(void); int main(void) { get_first_word(); while (strlen(word) != 4) get_another_word(); printf("\nSmallest word: %s\nLargest word: %s\n", smallest_word, largest_word); return 0; } void get_first_word(void) { get_word(); strcpy(smallest_word, word); strcpy(largest_word, word); } void get_word(void) { printf("Enter word: "); scanf("%20s", word); } void get_another_word(void) { get_word(); if (strcmp(word, smallest_word) < 0) strcpy(smallest_word, word); else if (strcmp(word, largest_word) > 0) strcpy(largest_word, word); }...
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } } return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...
Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...
Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...
devmem2.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include <ctype.h> #include <termios.h> #include <sys/types.h> #include <sys/mman.h> #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) #define MAP_SIZE 4096UL #define MAP_MASK (MAP_SIZE - 1) int main(int argc, char **argv) { int fd; void *map_base = NULL, *virt_addr = NULL; unsigned long read_result, writeval; off_t target; int access_type = 'w'; if(argc...
what's wrong with my code?????? #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXBINS 99 #define MAXCORS 26 #define MAXCUS 100 #define MAXPUR 10 /* datatype for a list of orders ----------------- */ typedef struct { int bin_order_number; char bin_order_char; }bin_order; typedef struct { int orderNo; bin_order orderbin; }order; typedef struct { int cusnumber; int n; /* number of the orders what the txt include */ order oo[MAXPUR+1]; }customer; typedef struct{ int n; /*number of the customers */ customer cc[MAXCUS+1];...
Explain the code and analyze the performance of algorithm #include<stdio.h> #include<string.h> #define NUM 100 #define maxint 10000 void dijkstra(int n,int v,int dist[],int prev[],int c[][NUM]) { int i,j; bool s[NUM]; for(i=1; i<=n; i++) { dist[i] = c[v][i]; s[i] = false; if (dist[i]>maxint) prev[i] = 0; else prev[i] = v; } dist[v] = 0; s[v] = true; for(i=1; i<n; i++) { int tmp = maxint; int u = v; for(j=1; j<=n; j++) if(!(s[j]) && (dist[j]<tmp)) { u = j; tmp = dist[j]; ...
#include <stdio.h> #include <stdlib.h> #include <strings.h> #include <unistd.h> #include <pthread.h> pthread_mutex_t mtx; // used by each of the three threads to prevent other threads from accessing global_sum during their additions int global_sum = 0; typedef struct{ char* word; char* filename; }MyStruct; void *count(void*str) { MyStruct *struc; struc = (MyStruct*)str; const char *myfile = struc->filename; FILE *f; int count=0, j; char buf[50], read[100]; // myfile[strlen(myfile)-1]='\0'; if(!(f=fopen(myfile,"rt"))){ printf("Wrong file name"); } else printf("File opened successfully\n"); for(j=0; fgets(read, 10, f)!=NULL; j++){ if (strcmp(read[j],struc->word)==0)...
I need little help with C language. I need to pass what I get from HexToBin(char* hexdec) into char* input so that what I got there it should pass it as string array parametr. Example: Enter IEEE-Hex: 40200000 Equivalent Binary value is : 01000000001000000000000000000000 Decimal Number: 2.5 #include <stdio.h> void HexToBin(char* hexdec) { long int i = 0; while (hexdec[i]) { switch (hexdec[i]) { case '0': printf("0000"); break;...