c - Errors in code. I do not know what category it falls under -
** I added the new code. I do not think there is a problem, but the program stopped after entering the item's code. What can I do to fix it ???
zero cart () {int code, amount; Float weight, value, total_weight, total_price1; Four products [20]; Switch (code) {case 1: product = "cement"; Weight = 20; Value = 18; break; Case 2: Product = "Concrete"; Weight = 30; Value = 25; break; Case 3: Product = "Ceramic Tile Floor"; Weight = 0.1; Value = 2.2; break; Case 4: Product = "foam insulation"; Weight = 0.1; Value = 2.2; break; Case 5: Product = "Fiber-Blocked Cement"; Weight = 35; Value = 50; break; Case 6: Product = "thick glass panel"; Weight = 20; Value = 50; break; Case 7: Product = "Thin Glass Panel"; Weight = 10.5; Value = 30; break; Case 8: Product = "Iron Beam"; Weight = 5; Value = 10; break; Case 9: Product = {"Iron Rod"; Weight = 1; Value = 5; break; Case 10: Product = "Plaster Board"; Weight = 10; Value = 15; break; Case 11: Product = "Mine Tiles"; Weight = 0.5; Value = 3; break; Case 12: Product = "Steel Beam"; Weight = 5; Value = 10; break; Case 13: Product = "Wooden Board"; Weight = 3; Value = 5; break; } Printf ("\ n Please enter the desired amount:"); Scanf ("% d", and zodiac); Total_weight = weight * amount; Total_price1 = price * amount; Printf ("So far, total weight in vehicle and total value% F kg and RM% 0.1F", total_weight, total_price1); }
The language I am using is the same. Above is the code for my program (not the whole thing). The problem is:
. C | 42 | Error: Type 'char [20]' by typing 'char *' while specifying to type incompatible types.
This error goes to all rows with the product. Did I make the array wrong? I want to set the variable product as wire and the product varies with each case. How do I declare variable products in the function?
In addition, how can I loop it if the user wants, then he can add another "product" and his car is in the cart. Then, add weight and value to total weight and value. And perhaps can be used to prevent the use of provincial products?
Finally, is there a way to simplify what I have done?
Thanks in advance
The code edited here is:
zero cart () {int code, amount; Float weight, value, total_weight, total_price1; Four * products; Printf ("Enter the code of the desired product \": "); Scanf ("% d", and code); Switch (code) {case 1: strakpy (product, "cement"); Weight = 20; Value = 18; break; Case 2: Streaky (product, "concrete"); Weight = 30; Value = 25; break; Case 3: Streaky (product, "ceramic tile bottom"); Weight = 0.1; Value = 2.2; break; Case 4: Streaky (product, "foam insulation"); Weight = 0.1; Value = 2.2; break; Case 5: Streaky (Product, "Fiber-Inferid Cement"); Weight = 35; Value = 50; break; Case 6: Streaky (product, "thick glass panel"); Weight = 20; Value = 50; break; Case 7: Streaky (product, "thin glass panel"); Weight = 10.5; Value = 30; break; Case 8: Streaky (Product, "Iron Beam"); Weight = 5; Value = 10; break; Case 9: Streaky (Product, "Iron Rod"); Weight = 1; Value = 5; break; Case 10: Streaky (Product, "Plaster Board"); Weight = 10; Value = 15; break; Case 11: Streaky (Product, "Mine Tiles"); Weight = 0.5; Value = 3; break; Case 12: Streaky (Product, "Steel Beam"); Weight = 5; Value = 10; break; Case 13: Streaky (Products, "Wooden Board"); Weight = 3; Value = 5; break; } Printf ("\ n Please enter the desired amount:"); Scanf ("% d", and zodiac); Total_weight = weight * amount; Total_price1 = price * amount; Printf ("So far, the total weight in the cart and total value is 0.2fkg and RM% 0.2f", total_weight, total_price1);
In this celebration [-Vinninnised] |
And after entering any code number my program stopped working.
In addition, how can I loop the program so that the user can enter the code of the product and want to shut it down the amount?
Okay. Therefore, I have fixed it with the following code:
char * product = "unknown";
But my program has still stopped working, it will not display the total weight and value.
You can not specify a constant string for char []
. For example
product = "cement";
Incorrectly you should use
Structio (Product, "Cement");
Comments
Post a Comment