Link to home
Start Free TrialLog in
Avatar of ojdc2004
ojdc2004Flag for United States of America

asked on

Assistance needed please

Hello,
Can someone please help me with my program, I just started my class this past week and the first requirement was to do a program with the following requirement: Create a struct that will have 2 things (Name of Snack and Price of snack), then create a one dimensional array of the data type mentioned. Input at least 8 snacks into the array. The program should just print out the name of the snack and the price, with no user input.
I know it is a poorly constructed program, but I have not had much time to study and it is due in 24hours, I would really appreciate your help.

// This program uses a struct to declare variables and an array to be displayed

#include <iostream>              // Basic input and output library
#include <string>
#include <sstream>
using namespace std;
   
// This section will provide global sturct type
struct Snacks
{
        float Name_Snack[25]; //Nema of the Snack
        float Snack_Price;   //Price of the Snack
}VendMachine;

//Void writeSnacks (char Array[]);

int main(int nArg, char* pszArgs[])
{
   
    Snacks Array[10];
   
        Array[0].Name_Snack="Snickers";
        Array[0].Snack_Price = 1.00;
        Array[1].Name_Snack = "Tootsie Roll";
        Array[1].Snack_Price = .95;
        Array[2].Name_Snack = "Milky Way";
        Array[2].Snack_Price = 1.10;
        Array[3].Name_Snack = "Skittles"
        Array[3].Snack_Price = 1.05;
        Array[4].Name_Snack = "M&M's";
        Array[4].Snack_Price = .80;
        Array[5].Name_Snack = "Lay's Potatoe Chips";
        Array[5].Snack_Price = 1.25;
        Array[6].Name_Snack = "Ruffles";
        Array[6].Snack_Price = 1.25;
        Array[7].Name_Snack = "Almond";
        Array[8].Snack_Price = 1.00;
       
        system("PAUSE");
        return 0;
}

void writeSnacks(char Array[])
{
    for(int i=0; Array[i] !='\0'; i++)
    {
        cout<< Array[i];
    }
}
       
        cout << "My snack machine contains:";
        for (it=Array.begin(); it!=Array.end(); ++it) cout <<" "<< *it;
        cout <<endl;
       
    delete [0] Array;
    return 0;
    }
}
Avatar of phoffric
phoffric

This is a C++ program. You will get more help if you Request Attention and add the C++ programming language zone.

What OS compiler are you using?

What exactly is your question. What kind of help specifically are you requesting? Did you try to compile this?

Here's one thing that is pretty clear:
Array[0].Name_Snack is an array of floats, and yet you are trying to set it to a literal string. That does not make sense.
Array[0].Name_Snack="Snickers";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jsmtek
jsmtek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Remember that EE policy does not permit us to write extensive code for you for assignments. As such, it is important that you submit your code and ask questions that we can assist you.
Avatar of ojdc2004

ASKER

Thank you for your assistance, it gave me a better understanding on how to write arrays.