Thread: Please take a look everyone!

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    1

    Lightbulb Please take a look everyone!

    Can anyone fix the errors for me, I should write the code in C program, but instead I wrote it in C++, it works fine in C++, but many on C when I compile with the C compiler. Please fix the errors for me in C program, thanks!

    This is the C program instruction, that I need to do:

    Students are asked to write code to compute and
    display a customer's
    bill for a takeout fast-food restaurant,

    (1) There are several menu items and their names and
    costs are as followed:

    Crab Cakes $3.75 Bruschetta $4.55
    Chicken $6.25 Fried Calamari $5.95

    (2) The price is reduced based on (a) the amount of
    items ordered
    and (b) the age groups (children, adults, or senior
    citizens) and
    note that state tax is also applied to the total price
    and it is
    the same for all age groups. The state tax, age and
    quantity discounts are as followed:

    Quantity discount for each item: 10% >=20 Orders
    7% >=10 Orders
    5% >=5 Orders
    Children Discount: 10%
    Senior Citizen Discount: 20%
    State Tax Percent: 4.5%

    (3) The program should (a) request the quantity of
    each item ordered,
    (b) request the input value from the Age Group as
    children [C],
    senior citizen [S], or adult [A], (c) calculate the
    subtotal, subtotal
    with discount, state tax, and the final total cost,
    and (d) display an itemized bill.

    (4) Run and enter the requested information.

    The example of a screen input/output is as followed:

    TAKE ORDER
    How many "Crab Cakes" ($3.75)? :20
    How many "Bruschetta" ($4.55)? :10
    How many "Chicken" ($6.25) :0
    How many "Fried Calamari" ($5.95)? :4

    Age group (S, C, A)? :S

    THE CUSTOMER ITEMIZED BILL
    Item Names Quantity Prices Quantity Discount

    Crab Cakes ($3.75) 20 $75.00 $67.50
    Bruschetta ($4.55) 10 $45.50 $42.32
    Fried Calamari ($5.95) 4 $23.80 $23.80

    SubTotal $144.30 $133.62
    Age Group Senior Citizen

    SubTotal (Age Group Discount) $106.89
    State Tax (%4.5) $4.81

    TOTAL $111.70


    And here is my C++ program, I should write it in C,
    too many errors when using C compiler, please fix it for me in C program, thanks!

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    double calculateDiscount(double &, double);
    
    int main()
    {
    	double cake=0.0, brus=0.0, chic=0.0, cala=0.0,
    stotal=0.0,agedis=1.0;
    	char age=' ';
    	const double tax = .045;	
    
    	cout << "TAKE ORDER" <<endl;
    	cout << "How many Crab Cakes ($3.75)? ";
    	cin  >> cake;	
    	cout << "How many Bruschetta ($4.55)? ";
    	cin  >> brus;
    	cout << "How many Chicken ($6.25)? ";
    	cin  >> chic;
    	cout << "How many Fried Calamari ($5.95)? ";
    	cin  >> cala; 
    	cout << "\n\nAge group (S,C,A)? ";
    	cin  >> age;
    
    	cout.setf(ios::fixed);
    	cout.setf(ios::showpoint);
    	cout.precision(2);
    
    	cout << "\n\nTHE CUSTOMER ITEMIZED BILL"<<endl;
    	cout << "Item Names Quantity Prices Quantity
    Discount\n\n";
    	if (cake !=0){
    		cout << "Crab Cakes ";
    		stotal +=calculateDiscount(cake,3.75);
    	}
    	if (brus !=0){
    		cout <<"Bruschetta ";
    		stotal +=calculateDiscount(brus,4.55);
    	}
    	if (chic !=0){
    		cout <<"Chicken ";
    		stotal +=calculateDiscount(chic,6.25);	
    	}
    	if (cala !=0){
    		cout <<"Fried Calamari ";
    		stotal +=calculateDiscount(cala,5.95);
    	}
    	cout << "\nSubTotal $"<<(cake + brus + chic + cala)<<
    " $"<< stotal<<endl;
    	cout << "Age Group ";
    
    	switch (age){
    		case 'S' : cout << "Senior Citizen"<<endl; agedis =
    .20; break;			
    		case 'C' : cout << "Children"<<endl; agedis = .10;
    break;
    		case 'A' : cout << "Adults"<<endl;break;
    	}
    	cout << "\nSubTotal (Age Group Discount)$"<<stotal
    -stotal*agedis<<endl;
    	cout << "State Tax (%4.5)
    $"<<((stotal-(stotal*agedis))*tax)<<endl;
    
    return 0;
    }
    
    double calculateDiscount(double &order, double price){
    	double total=0.0;
    	total = order*price;
    	if(order >= 20)
    		total = total - (total * .10);
    	else if(order >=10)
    		total = total - (total* .07);
    	else if(order >=5)
    		total = total - (total * .05);
    	if (total != 0)
    		cout << "($"<<price<<") "<< order <<"
    $"<<order*price<<" $"<<total<<endl;
    	order = order*price;
    	return total;
    }
    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    Umm, how about you have a go at fixing the errors yourself.
    Here's some code to get you started
    Code:
    (cin && cout) != C;
    (cin && cout) == C++;
    Demonographic rhinology is not the only possible outcome, but why take the chance

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    26

    Wink

    Hm it's kind of hard to read your code but if

    you are a C begginer the first think you should know is what

    exacly you need first. You said that in C++ it works all you need

    to change in here if you are begginer just the cin>> is almost the

    same as "scanf" if you know what it does and also if you wont to

    use printf instead of cout ok i hope it helps
    C++ Is cool

Popular pages Recent additions subscribe to a feed