Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,855 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,347 people online right now. Registration is fast and FREE... Join Now!




Menu Driven Program

2 Pages V  1 2 >  
Reply to this topicStart new topic

Menu Driven Program, beginners program

bdstarter
21 Feb, 2007 - 07:15 PM
Post #1

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 11


My Contributions
hello
QUOTE

Write a menu-driven program called hw4 that calculates the total price for a picnic lunch that the user is purchasing for a group of friends. The user is first asked to enter her budget for the lunch. She has the option of buying apples, cheese, and bread. Set the price per apple, price per pound of cheese, and price per loaf of bread in constant variables. Use a nested repetition/selection structure to ask the user what type of item and how much of each item she would like to purchase. Keep a running total of the items purchased inside the loop. Exit the loop if the total has exceeded the user?s budget. In addition, provide a sentinel value that allows the user to exit the purchasing loop at any time.
Input is from the keyboard. Output is to the screen.

CODE

/// HW4.cpp : program calculates the total price for a picnic lunch .
//

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

int main ()

{
double budget;
const double apples=1.5;
const double cheese=3;
const int bread=1;
double total = 0;
char choice;
int count;


cout << "       picnic price calculates     " << endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
cout <<"enter your budget for the lunch ?";
cin >>budget;
cout <<endl;
cout <<"*****************menu*****************"<<endl;
cout <<"*    A-Apple    B-Berd   C-Cheese    *"<<endl;
cout <<"*      1.5$      1$        3$        *"<<endl;
cout <<"**************************************"<<endl;
cout <<endl;
cout <<"Enter you Option : ";
cin >> choice;

whlie (choice != 'Q')&&(total < budget);

{
    switch (choice)
    {
    case 'A':
    case 'a':
        cout << "How many apples?"
        cin >> count;
        total+=(count * apples)
        break;
    }
    {
    case 'B':
    case 'b':
        cout << "How many loafs of Bread?"
        cin >> count;
        total+=(count * bread)
        break;
    }
    {
    case 'C':
    case 'c':
         cout << "How many pound of cheese?"
        cin >> count;
        total+=(count * bread)
        break;
    }
    cout << total;    
}
return 0;

i get a lot of errors
and dont now wat to add to the prog to make it woke(confused)
thanks for your time and hellp

This post has been edited by Videege: 21 Feb, 2007 - 07:52 PM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Menu Driven Program
21 Feb, 2007 - 07:18 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,351



Thanked: 51 times
Dream Kudos: 25
My Contributions
first and foremost, you need to end each command statement with a semi colon - you are missing the semi colons on several key statements. Another issue is that select case statement is not syntaxed correctly as is.

Can you post the errors you are receiving?
User is online!Profile CardPM
+Quote Post

bdstarter
RE: Menu Driven Program
21 Feb, 2007 - 07:24 PM
Post #3

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 11


My Contributions
Compiling...
stdafx.cpp
Compiling...
HW4.cpp
\desktop\hw\hw4\hw4\hw4.cpp(38) : error C3861: 'whlie': identifier not found
\desktop\hw\hw4\hw4\hw4.cpp(46) : error C2146: syntax error : missing ';' before identifier 'cin'
c\hw\hw4\hw4\hw4.cpp(48) : error C2143: syntax error : missing ';' before 'break'
\hw\hw4\hw4\hw4.cpp(51) : error C2046: illegal case
\hw\hw4\hw4\hw4.cpp(52) : error C2046: illegal case
\hw\hw4\hw4\hw4.cpp(54) : error C2146: syntax error : missing ';' before identifier 'cin'
c:\documents and settings\starptv\desktop\hw\hw4\hw4\hw4.cpp(56) : error C2143: syntax error : missing ';' before 'break'
\hw\hw4\hw4\hw4.cpp(56) : error C2043: illegal break
\hw\hw4\hw4\hw4.cpp(59) : error C2046: illegal case
\hw\hw4\hw4\hw4.cpp(60) : error C2046: illegal case
\hw\hw4\hw4\hw4.cpp(62) : error C2146: syntax error : missing ';' before identifier 'cin'
desktop\hw\hw4\hw4\hw4.cpp(64) : error C2143: syntax error : missing ';' before 'break'
\desktop\hw\hw4\hw4\hw4.cpp(64) : error C2043: illegal break
Build log was saved at \Desktop\HW\HW4\HW4\Debug\BuildLog.htm"
HW4 - 13 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


is thes good

switch (choice)
{
case 'A':
case 'a':
cout << "How many apples?"
cin >> count ;
total+=(count * apples);
break;
}

User is offlineProfile CardPM
+Quote Post

WolfCoder
RE: Menu Driven Program
21 Feb, 2007 - 07:29 PM
Post #4

ギュウ~
Group Icon

Joined: 5 May, 2005
Posts: 3,715



Thanked: 8 times
Dream Kudos: 1450
My Contributions
CODE

// Your code
switch (choice)
{
case 'A':
case 'a':
cout << "How many apples?"
cin >> count;
total+=(count * apples);
break;
}


You're missing a semicolon after the cout line. Also, here is an example:

CODE

switch(variable)
{
   case 1:
   // do stuff
   break;
   case 2:
   case 3:
   // 2 and 3 do stuff here
   break;
}


You're code has copies of cases in brackets. You can surround it all in the single switch statement since the variable inside is always what you want to compare inside the statement.

If you want to handle a case where none of the previous cases match, use the default statement.

CODE

switch(variable)
{
   case 1:
   // do stuff
   break;
   case 2:
   case 3:
   // 2 and 3 do stuff here
   break;
   default:
   // Not 1, 2, or 3 since none of them match, do stuff in here then
   break;
}


This post has been edited by WolfCoder: 21 Feb, 2007 - 07:38 PM
User is offlineProfile CardPM
+Quote Post

bdstarter
RE: Menu Driven Program
21 Feb, 2007 - 07:36 PM
Post #5

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 11


My Contributions
ok
CODE

    {
    case 'C':
    case 'c':
         cout << "How many pound of cheese?";
        cin >> count;
        total+=(count * bread);
        break;
    }


Errors


\desktop\hw\hw4\hw4\hw4.cpp(38) : error C3861: 'whlie': identifier not found
\desktop\hw\hw4\hw4\hw4.cpp(51) : error C2046: illegal case
desktop\hw\hw4\hw4\hw4.cpp(52) : error C2046: illegal case
\desktop\hw\hw4\hw4\hw4.cpp(56) : error C2043: illegal break
desktop\hw\hw4\hw4\hw4.cpp(59) : error C2046: illegal case
\desktop\hw\hw4\hw4\hw4.cpp(60) : error C2046: illegal case
\desktop\hw\hw4\hw4\hw4.cpp(64) : error C2043: illegal break

thank for your help
User is offlineProfile CardPM
+Quote Post

WolfCoder
RE: Menu Driven Program
21 Feb, 2007 - 07:41 PM
Post #6

ギュウ~
Group Icon

Joined: 5 May, 2005
Posts: 3,715



Thanked: 8 times
Dream Kudos: 1450
My Contributions
The first error is a simple mistake since it is spelled while. The others seem as though you need to make the switch statements look something like my example.
User is offlineProfile CardPM
+Quote Post

bdstarter
RE: Menu Driven Program
21 Feb, 2007 - 07:46 PM
Post #7

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 11


My Contributions
CODE
whlie (choice != 'Q')&&(total < budget);

{
    switch (choice)
    {
    case 'A':
    case 'a':
        cout << "How many apples?";
        cin >> count;
        total+=(count * apples);
        break;
    
    
    case 'B':
    case 'b':
        cout << "How many loafs of Bread?";
        cin >> count;
        total+=(count * bread);
        break;
    
    
    case 'C':
    case 'c':
         cout << "How many pound of cheese?";
        cin >> count;
        total+=(count * bread);
        break;
    }

    cout << total;    
}
return 0;
}


errors

------ Build started: Project: HW4, Configuration: Debug Win32 ------
Compiling...
stdafx.cpp
Compiling...
HW4.cpp
\hw\hw4\hw4\hw4.cpp(38) : error C3861: 'whlie': identifier not found
Build log was saved at "\Desktop\HW\HW4\HW4\Debug\BuildLog.htm"
HW4 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


getting better
User is offlineProfile CardPM
+Quote Post

WolfCoder
RE: Menu Driven Program
21 Feb, 2007 - 07:51 PM
Post #8

ギュウ~
Group Icon

Joined: 5 May, 2005
Posts: 3,715



Thanked: 8 times
Dream Kudos: 1450
My Contributions
Remember, it is not whlie,

it is while.

Switch the i and the l around.

This post has been edited by WolfCoder: 21 Feb, 2007 - 07:51 PM
User is offlineProfile CardPM
+Quote Post

bdstarter
RE: Menu Driven Program
21 Feb, 2007 - 07:52 PM
Post #9

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 11


My Contributions
CODE
  while (choice != 'Q') \\need a semicolon herr??\\ && ( total < budget);

{
    switch (choice)
    {
    case 'A':
    case 'a':
        cout << "How many apples?";
        cin >> count;
        total+=(count * apples);
        break;



error

error C2143: syntax error : missing ';' before '&&'
User is offlineProfile CardPM
+Quote Post

WolfCoder
RE: Menu Driven Program
21 Feb, 2007 - 07:59 PM
Post #10

ギュウ~
Group Icon

Joined: 5 May, 2005
Posts: 3,715



Thanked: 8 times
Dream Kudos: 1450
My Contributions
while (choice != 'Q') \\need a semicolon herr??\\ && ( total < budget);

For regular while statements, you do not need a semicolon.

Remember to surround everything in a while statement with () characters.

Since your statement is (choice != 'Q') && ( total < budget), try
((choice != 'Q') && ( total < budget)).

Put it all together to form a regular while statement.
User is offlineProfile CardPM
+Quote Post

bdstarter
RE: Menu Driven Program
21 Feb, 2007 - 08:21 PM
Post #11

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 11


My Contributions
ok
no errors in the build

when i start to debug it gets stuck in //while ((choice != 'Q')&&(total < budget));

i am using visual c++ 2005 express edition
User is offlineProfile CardPM
+Quote Post

bdstarter
RE: Menu Driven Program
21 Feb, 2007 - 08:33 PM
Post #12

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 11


My Contributions
fond the problem no semicolon after the statement
while ((choice != 'Q')&&(total < budget))



thank you for you help
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 1/8/09 10:30AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month