We help IT Professionals succeed at work.

codes for program

tsburt
tsburt asked
on
258 Views
Last Modified: 2010-04-15
can someone help me with the codes for a program that does this?
thanks


Write a program to do the following:
Ï input a number for a menu entry desired from the user
Ï use a switch statement to determine which item is selected
Ï the program should start with $0.00 as the total price
Ï a selected item should print as confirmation the item selected and a subtotal after adding the item price
Ï run the program and select each item at least once
Ï select to print the total price
Ï select to exit the program
Menu to be printed:
 Place your order
1 Burger
2 Fries
3 Soda
4 Shake
5 Total the price
6 Exit the program
Please enter which you want: 
Prices are as follows:
Burger $2.75
Fries $1.25
Soda $1.10
Shake $1.95
Comment
Watch Question

Author

Commented:
i'm sorry for not asking the right way....
let's jsiut say i'm stuck right here have no clue what to do next or what i'm doing wrong..
this is what i got so far.....

/* A simple menu . */
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#define menu  4
#define prices  4

int grade[menu][prices];

void enter_menu(void);
int get_price(int num);
void disp_price(int g[][menu]);

int main(void)
{
  char ch, str[80];

  for(;;) {
    do {
      printf("(E)nter menu\n");
      printf("(R)eport price\n");
      printf("(Q)uit\n");
      gets(str);
      ch = toupper(*str);
    }

printf("burger");
printf("fries");
printf("soda");
printf("shake");

fridomCEO/Programmer
CERTIFIED EXPERT

Commented:
I'd argue we've seen worse attempts. Howerver there is  quite a lot wrong with it. To the OP:
Do one thing at a time.
1) you've asked for a menu elswhere, wrap it up in one function, test this function
2) nothing in the requirements suggest the loop you wrote
3) keeping elements together which seem to belong together can be done in arrays

If that all is too much yet, Start smaller. Just write the stuff for one Order.
The point you always should keep on your mind. Start with the thing you know, and implement it.
Then combine the elements and you get something larger. Always test your assumptions and it's really not a
bad idea to step through your code with a debugger to see wheter you assumptions are right.

Regards
Friedrich
CERTIFIED EXPERT
Top Expert 2009

Commented:
>> Ï input a number for a menu entry desired from the user

Take a look at the standard scanf function (in <stdio.h>) :

        http://www.cplusplus.com/reference/clibrary/cstdio/scanf.html


>> Ï use a switch statement to determine which item is selected

Do you know what a switch is and how to use it ?


>> Ï the program should start with $0.00 as the total price

What kind of variable do you want for this ? An int ? A char ? A float ? Something else ?


>> Ï a selected item should print as confirmation the item selected and a subtotal after adding the item price

You've already used printf ... You'll just have to play with it a bit more to show multiple values on the same line.


>> Ï run the program and select each item at least once
>> Ï select to print the total price
>> Ï select to exit the program

I can't help you with that ;)

Author

Commented:
ok here we go again.....
 void menu (void)
{
char ch;
printf("1. burger");
printf("2. fries");
printf("3. soda");
printf("4. shake");
printf("5. total the price");
printf("6. exit the program");
printf(" please enter which you want");
ch = getchar(); /* read the seletions from the keyboard */

i'm stuck on how the price should be put in...is this right now?
or am i at least trying?
CEO/Programmer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2009

Commented:
Note that you don't have any newlines in your menu - everything will be shown on teh same line. Use the \n character for that.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.