Given the number of commodities bought, create a program that computes the total amount purchased in a fast food center. Assume that the following unit price of each commodity
Fried Chicken= 29.75
Cheese Burger= 25.00
French Fries= 18.50
Soft Drinks=14.25

Recommended Answers

All 9 Replies

Which part are you having trouble with?

I don't know how to create a program with that problem :(

Get a input of each 1... and calculate the values and total? Come on mate give it a try at least... don't ask people to do your project for you?

I don't know how to create a program with that problem :(

That's a textbook lazy response right there. If you already knew how to create that program, it wouldn't have been assigned. Figure it out, we all had to at some point.

First, get out a pen and pencil. Think about how things work when you go to the local McDonalds (or whatever) and write down your thoughts. Then, start thinking about how you can replicate that behavior. Ask yourself questions about the program and write down your answers.

  • Are there any constants required? What are their dataTypes, names, and values? (HINT: This information is all provided in your scenario description.)
  • Do I need any counter variables? What dataType should they be?
  • Do I need any prompts? For what? How should they be formatted? What dataTypes should the input variables be?
  • Do I need any temporary values of any kind?
  • What, if any, mathematical formula(s) will I need?
  • etc.

Once you have your answers, begin creating an algorithm that addresses what you've come up with. Once you have an algorithm, start writing your code.

commented: Brilliant description and planning structure... also encourages one to learn as much as possible by him/her - self +1

haha,you to learn it out yourself step by step.but i will help you this time.

/*Given the number of commodities bought, create a program that computes the
total amount purchased in a fast food center. Assume that the following unit
price of each commodity*/

#include <iostream.h>
void main(){
int a,b,c,d;     //a=Fried Chicken,b=Cheese Burger,c=French Fries,d=Soft Drinks//
float total;    //total price for all commodity//

cout<<"Enter the number of commodities bought."<<endl;
cout<<"Fried Chicken:";
cin>>a;
cout<<"Cheese Burger:";
cin>>b;
cout<<"French Fries:";
cin>>c;
cout<<"Soft Drinks:";
cin>>d;

total=(a*29.75)+(b*25.00)+(c*18.50)+(d*14.25);

cout<<"Total:"<<total;
}

This is 1 of the solution for your question. But i believe there is other way.

commented: Seriously? -3
commented: Please don't spread non standard code around -2

Uhm... I dont want to sound like an ass but that is not really helping... we told him to at least try... everyone on this forum will help some-one if they at least try themselves... be it error handling or code correction... but giving them results is just strengthening their lack of knowledge

commented: Well said. +13

hmm,i see.may be i should let him try 1st.because this is first time i trying to solve people's problem.XP,will do.

haha,you to learn it out yourself step by step.but i will help you this time.

/*Given the number of commodities bought, create a program that computes the
total amount purchased in a fast food center. Assume that the following unit
price of each commodity*/

#include <iostream.h>
void main(){
int a,b,c,d;     //a=Fried Chicken,b=Cheese Burger,c=French Fries,d=Soft Drinks//
float total;    //total price for all commodity//

cout<<"Enter the number of commodities bought."<<endl;
cout<<"Fried Chicken:";
cin>>a;
cout<<"Cheese Burger:";
cin>>b;
cout<<"French Fries:";
cin>>c;
cout<<"Soft Drinks:";
cin>>d;

total=(a*29.75)+(b*25.00)+(c*18.50)+(d*14.25);

cout<<"Total:"<<total;
}

This is 1 of the solution for your question. But i believe there is other way.

Nice... :(

For something like this, you don't really want to "solve" their problem per se. The appropriate approach would be to gently guide them to their own solution. That way, they have to think it through and learn it better.

While we're on the topic, a couple critiques on your code:

  • There is no formatting. Without proper formatting, the code is very difficult to read so it's not easy to see what statements are grouped together and how information's scope changes.
  • Your header is outdated, new code really should use <iostream> instead.
  • Your main() is declared void it should be int.
  • You haven't initialized any variables. What happens if the user doesn't want any French Fries? How many is the system going to think they ordered?
  • You're using "magic numbers" instead of constants for the unit prices. In this case, they work, but it's generally not a good idea because they make it harder to edit the code in the future.
  • Because main() is required to return int, you also need a return statement at the end of the program.

hmm... testing running program is difficult part, so let them to learn... giving sample program is good but running program completely is really difficult. but comparing the output statement to your codes is one way of learning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.