Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

codes for program

Posted on 2007-10-11
8
Medium Priority
?
238 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
0
Comment
Question by:tsburt
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Author Comment

by:tsburt
ID: 20062924
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");

0
 
LVL 24

Expert Comment

by:fridom
ID: 20063413
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
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20063454
>> Ï 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 ;)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:tsburt
ID: 20063674
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?
0
 
LVL 24

Accepted Solution

by:
fridom earned 1500 total points
ID: 20063834
enum OrdetItemsIndex = {IT_BURGER=1, IT_FRIES...., IT_SHAKE, IT_MAX};

struct OrderItem {
      char *what;
     double price;
}

struct OrderItems orderItems [IT_MAX] = {{Burger, 0.50}, ...

Index into it like this
if (ch => 1 && ch < 5)
 printf("You've choosen index %d with the following thing %s and a price of %g", ch, orderItems[ch].what,
orderItems[ch].price};
else ...

As written before, why not first implement menu correctly? and doing other things later?

Friedrich

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20064113
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question