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

Join 137,267 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,490 people online right now. Registration is fast and FREE... Join Now!




chips and salsa

 
Reply to this topicStart new topic

chips and salsa

sonzai
6 Nov, 2006 - 11:23 PM
Post #1

New D.I.C Head
*

Joined: 31 Oct, 2006
Posts: 31


My Contributions
ok I have everything good...
except how do I change the highest and lowest values into names
something like:
The highest selling product is mild.
The lowest selling product is hot.

CODE
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

double sum(double array[], int salsa)
{
       double total = 0;
      
       for (int count = 0; count < salsa; count++){
           total += array[count];
           }
       return total;
}

double getHightest(double array[], int salsa)
{
       double highest;
      
       highest = array[0];
       for (int count = 1; count < salsa; count++){
           if (array[count] > highest)
           highest = array[count];
           }
           return highest;
}

double getLowest(double array[], int salsa)
{
       double lowest;
      
       lowest = array[0];
       for (int count = 1; count < salsa; count++)
       {
           if (array[count] < lowest)
              lowest = array[count];
              }
              return lowest;
}

int main()
{
    const int SALSA = 5;
    double n_jars[SALSA];
    string name[SALSA] = { "mild", "medium", "sweet", "hot", "zesty" };
    double total;
    double highest;
    double lowest;
    
    cout << "Enter the number of jars sold for: " << endl;
    for ( int count = 0; count < SALSA; count++ ){
        cout << name[count] << ": ";
        cin >> n_jars[count];
        }
        
        for ( int count = 0; count < SALSA; count++ ){
            cout << "The sales for " << name[count] << " is " << n_jars[count] << endl;
            }
            
            total = sum(n_jars, SALSA);
            
            highest = getHightest(n_jars, SALSA);
            
            lowest = getLowest(n_jars, SALSA);
            
            cout << "The total amount of sales is   " << total << endl;
            cout << "The highest selling product is " << highest << endl;
            cout << "The lowest selling product is  " << lowest << endl;
}

User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Chips And Salsa
6 Nov, 2006 - 11:51 PM
Post #2

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
frequently you should assign it inititally...then comapre mild, medium..etc..


User is offlineProfile CardPM
+Quote Post

ZlxA
RE: Chips And Salsa
7 Nov, 2006 - 12:02 AM
Post #3

New D.I.C Head
*

Joined: 6 Nov, 2006
Posts: 10


My Contributions
What you should be doing is use highest and lowest as the element of your array which contains the name of salsa's for which you want to print out. You would do so like this:

cout << "The highest selling product is " << name[highest] << endl;
cout << "The lowest selling product is " << name[lowest] << endl;

But you will need to make other adjustments to your code. First off since it will store an array element, you should make highest and lowest integers and not doubles, and likewise you will need to return integers instead of doubles from your function. Secondly, you are putting the actual amount of the jars of each type of salsa into highest and lowest, when you should be putting the element number, i , into it.
User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Chips And Salsa
7 Nov, 2006 - 12:08 AM
Post #4

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
huh.gif

you just pointing to an index...


not the result...


User is offlineProfile CardPM
+Quote Post

ZlxA
RE: Chips And Salsa
7 Nov, 2006 - 02:03 PM
Post #5

New D.I.C Head
*

Joined: 6 Nov, 2006
Posts: 10


My Contributions
QUOTE(NyeNye @ 7 Nov, 2006 - 01:08 AM) *

huh.gif

you just pointing to an index...


not the result...


He has an array which contains the choices of results he wants to print out. Therefore he just needs to find which index holds the highest and lowest and then print out that element of the array.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:33PM

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