Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#pragma warning(disable:4996)
int main(void) {
	// Variable declarations
	int t = 0;
	float k, y, u, i;
	int a, b, c, d;
	int p;
	float  add, tt, f;
	char name[30], ic[20];
	char addr[50];

	//The personal details of customer //
	printf("\n=================================================================================\n");
	printf("\n Vegetable ordering system\n");
	printf("\n=================================================================================\n");
	printf("Please enter your full name     :");
	scanf(" %[^\n]", &name);
	printf("Please enter your ic number     :");
	scanf("%s", &ic);
	printf("Please enter your phone number     :");
	scanf("%d", &p);
	printf("Please enter your home address     :");
	scanf(" %[^\n]", &addr);
	printf("\n==================================================================================\n");
	printf("The customer name is  %s  and the ic number is %s \n", name, ic);
	printf("The customer who is come from come from %s", addr);
	printf("\n==================================================================================\n");

	//Order part of program//
	printf("\n==================================================================================\n");
	printf(" Enter the order quetity purchase \n");
	printf("\n==================================================================================\n");
	printf("Please order the package A        :");
	scanf("%d", &a);
	printf("Please order the package B        :");
	scanf("%d", &b);
	printf("Please order the package C        :");
	scanf("%d", &c);
	printf("Please order the package D        :");
	scanf("%d", &d);
	printf("\n==================================================================================\n");

	if (a, b, c, d > t) {
		printf("%d", a - t);

		k = (24.5) * a;
		printf("\nPackages  A              :RM%.2f\n", k);

		y = (26.5) * b;
		printf("\nPackages  B              :RM%.2f\n", y);

		u = (26.5) * c;
		printf("\nPackages  C              :RM%.2f\n", u);

		i = (24.5) * d;
		printf("\nPackages  D             :RM%.2f\n\n", i);

		//The addition part for total cost for customer to pay//
		add = k + y + u + i;
		tt = add + 5.90;
		f = tt - (0.15 * tt);

		if (add > 100) {
			printf("Total                                              =RM%.2f\n", add);
			printf("The delivery fee which is fixed                    =RM5.90\n          ");
			printf("\n==================================================================================\n");
			printf("The total price for customer need to pay with 15% discount          =RM%.2f\n", f);
			printf("\n==================================================================================\n");
		else (add<100)
		printf("Total                                              =RM%.2f\n", add);
		printf("\n==================================================================================\n");
		printf("The total price for customer need to pay       =RM%.2f\n", tt);
		printf("\n==================================================================================\n");
			system("pause");
			return 0;
		}
	}
}


What I have tried:

i want to do the if else function but there are a bit problem how can i do it

Please help me thanks
Posted
Updated 17-Aug-21 10:28am
Comments
jeron1 16-Aug-21 20:58pm    
I believe the if statement will act on the last entry, the "d < t" portion, the previous entries would be thrown away. What condition(s) do you want to be true in order to execute the contents in the if block?
The Other John Ingram 16-Aug-21 21:41pm    
i would use a swich/case statement instead
switch(t)
{
case a:
case b:
...
Patrice T 17-Aug-21 0:21am    
What your 'if else function' is supposed to do ?

I see two issues with your conditional expressions. The indentation is a bit messed up so that makes the second one a little harder to see. Here is your logic with revised indentation :
C++
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#pragma warning(disable:4996)

int main(void)
{
    // Variable declarations
    int t = 0;
    float k, y, u, i;
    int a, b, c, d;
    int p;
    float  add, tt, f;
    char name[30], ic[20];
    char addr[50];

    //The personal details of customer //
    printf("\n=================================================================================\n");
    printf("\n Vegetable ordering system\n");
    printf("\n=================================================================================\n");
    printf("Please enter your full name     :");
    scanf(" %[^\n]", &name);
    printf("Please enter your ic number     :");
    scanf("%s", &ic);
    printf("Please enter your phone number     :");
    scanf("%d", &p);
    printf("Please enter your home address     :");
    scanf(" %[^\n]", &addr);
    printf("\n==================================================================================\n");
    printf("The customer name is  %s  and the ic number is %s \n", name, ic);
    printf("The customer who is come from come from %s", addr);
    printf("\n==================================================================================\n");

    //Order part of program//
    printf("\n==================================================================================\n");
    printf(" Enter the order quetity purchase \n");
    printf("\n==================================================================================\n");
    printf("Please order the package A        :");
    scanf("%d", &a);
    printf("Please order the package B        :");
    scanf("%d", &b);
    printf("Please order the package C        :");
    scanf("%d", &c);
    printf("Please order the package D        :");
    scanf("%d", &d);
    printf("\n==================================================================================\n");

    if (a, b, c, d > t)
    {
        printf("%d", a - t);

        k = (24.5) * a;
        printf("\nPackages  A              :RM%.2f\n", k);

        y = (26.5) * b;
        printf("\nPackages  B              :RM%.2f\n", y);

        u = (26.5) * c;
        printf("\nPackages  C              :RM%.2f\n", u);

        i = (24.5) * d;
        printf("\nPackages  D             :RM%.2f\n\n", i);

        //The addition part for total cost for customer to pay//
        add = k + y + u + i;
        tt = add + 5.90;
        f = tt - (0.15 * tt);

        if (add > 100)
        {
            printf("Total                                              =RM%.2f\n", add);
            printf("The delivery fee which is fixed                    =RM5.90\n          ");
            printf("\n==================================================================================\n");
            printf("The total price for customer need to pay with 15% discount          =RM%.2f\n", f);
            printf("\n==================================================================================\n");
        }
        else (add<100)
        {
            printf("Total                                              =RM%.2f\n", add);
            printf("\n==================================================================================\n");
            printf("The total price for customer need to pay       =RM%.2f\n", tt);
            printf("\n==================================================================================\n");
        }
        system("pause");
        return 0;
    }
}
I revised the braces on the second if and the else that check add. That may not be correct but your intentions were difficult to decipher with the code as it was.

The first else expression is unlikely to be what you intend. Here is a guess at your actual intent :
C++
if( ( a > t ) && ( b > t ) && ( c > t ) && ( d > t ) )
{
}
or you might want to test each one independently :
C++
if( a > t )
{
    k = (24.5) * a;
    printf("\nPackages  A              :RM%.2f\n", k);
}
if( b > t )
{
    y = (26.5) * b;
    printf("\nPackages  B              :RM%.2f\n", y);
}
if( c > t )
{
    u = (26.5) * c;
    printf("\nPackages  C              :RM%.2f\n", u);
}
if( d > t )
{
    i = (24.5) * d;
    printf("\nPackages  D             :RM%.2f\n\n", i);
}
I find it helpful to use braces almost all the time, even when it is not necessary. It can make your code a little easier to read and it is definitely easier to modify and maintain.
 
Share this answer
 
The description of the error is not particularly precise.
Assuming that the logic is correct, there is an avoidable syntax problem with if else.
Additionally, curly brackets seem to be wrong.
I guess how it could be right:
C++
int main(void) 
{
  // ....
  if (a, b, c, d > t)
    {
	// ....
	if (add > 100) {
		printf("Total                                          =RM%.2f\n", add);
		printf("The delivery fee which is fixed                =RM5.90\n");
		// ....
		}
	else { // (add<100) 
		printf("Total                                          =RM%.2f\n", add);
		// ....
		}
	}

	system("pause");
	return 0;
}
 
Share this answer
 
v2
Comments
Rick York 17-Aug-21 18:10pm    
You have three opening braces and four closing braces. That can't be right.
merano99 18-Aug-21 17:58pm    
Yes you are right. The text has been shortened and there is still an open if bracket in the original. I added. I´m not shure what it does. The suggestions in your solution would certainly be clearer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900