Welcome to Dream.In.Code
Getting C++ Help is Easy!

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




Control Structure and Array Issues

 
Reply to this topicStart new topic

Control Structure and Array Issues, Having difficulty with Arrays my control structure and vars

merkalerkin
11 Apr, 2007 - 11:08 AM
Post #1

New D.I.C Head
*

Joined: 11 Apr, 2007
Posts: 3


My Contributions
So the idea of this program is to display menu options, total those options, and display the selections made with the total.....
I've been stuck on this for too long now and could not find the answers in other posts... Any help would be great....As you can see i got to my array and then had issues as to how to input those selections if they were chosen as characters... not to mention displaying and totaling those selections without getting scientific notation crazy.gif
CODE
using namespace std;

#include<iostream>


int main()
{          
int menuitems[4];
double A;
double B;
double C;
double D;
double E;
int x;

A=2.99;
B=3.99;
C=1.99;
D=1.49;
E=2.49;
double total;
cout<<"Welcome to GoodBurger, May I take your order?"<<endl;
system("pause");
cout<<"A-Hamburger.......$2.99"<<endl;
cout<<"B-Cheese Burger...$3.99"<<endl;
cout<<"C-French Fries....$1.99"<<endl;
cout<<"D-Soft Drink......$1.49"<<endl;
cout<<"E-Milk Shake......$2.49"<<endl;
cout<<" "<<endl;
cout<<"Enter the corresponding letter of the menu item you would like..."<<endl;
cout<<"When you are ready for your total, Type Done..."<<endl;
for(x=0;x<4;x++)
{
    cout<<"Enter your selection one item at a time and press enter"<<endl;
    cin>>menuitems[x];
                      if(menuitems[0]==A)
                      {
                       menuitems[0]=2.99;
                      }
                      
    
    
    
    
    
}
total=menuitems[0]+menuitems[1]+menuitems[2]+menuitems[3]+menuitems[4];
cout<<"You're Total Is:"<<total<<endl;
system("pause");
}

User is offlineProfile CardPM
+Quote Post

merkalerkin
RE: Control Structure And Array Issues
11 Apr, 2007 - 02:25 PM
Post #2

New D.I.C Head
*

Joined: 11 Apr, 2007
Posts: 3


My Contributions
biggrin.gif anyone????? biggrin.gif
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Control Structure And Array Issues
11 Apr, 2007 - 02:33 PM
Post #3

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Couple of things are immediately evident.

1. You have declared an array of integers, but at one point in the program, try to assign a double value. The value will be truncated.
2. Each time through the loop, you are comparing an assigning values to the first index only - it never changes.
3. cin>>menuitems[x]; What are you expecting the user to enter? the price? If so, the price is of type double, and you are trying to assign it to an integer value. A character? Same issue.
4. if(menuitems[0]==A) Since A holds a double value, and the array is comprised of integers, there will never be a match here.
5. You have declared your main function as having a return type of int (correct), but not returned such a value upon function exit.

Just a few thoughts on what needs to be adjusted.
User is offlineProfile CardPM
+Quote Post

merkalerkin
RE: Control Structure And Array Issues
11 Apr, 2007 - 03:43 PM
Post #4

New D.I.C Head
*

Joined: 11 Apr, 2007
Posts: 3


My Contributions
Thank you very much for replying... you've deff. got me going in the right direction.. So i've changed all of my variables to integers and rounded my numbers for simplicity and because they'e ints.... now if i want the user to use characters as input, A,B,C,D,or E do i need to declare them as char or int? and or set them equal to the corresponding price? or could I just declare A-E and test the user input in a switch/if/for to set each subscript equal to a value declared and initialized in a different var?
very sloppy i know, and apologize.... I just feel like i'm only missing some very basic elements in order to get this to work... Thanks a million once again
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:43PM

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