82.5k views
5 votes
Write a program that allows you to enter grocery item names into an array of strings and the cost of each item in an array of doubles. At the beginning of the program prompt the user to enter the total number of items they will be entering. Max value of 100. After entering the item names and cost, the application should display the names and cost and total cost of all items.

User Kelsier
by
4.5k points

1 Answer

4 votes

Answer:

#include <iostream>

#include <iomanip>

using namespace std;

int main(){

//declare arrays

string ItemName[100];

double ItemCost[100]={0.0};

//declare variable

string name="";

double Total=0.0;

int NumItems=0;

cout<<"Enter number of grocery item you will be entering";

cin>>NumItems

cout<<"\\";

if (NumItems>100)

{

cout<<"Enter grocery items less than 100"

cin>>NumItems

cout<<"\\";

}

for (int i=1;i>=NumItems;i++)

{

cout<<"Please enter the item name in one word only, Example: icecream\\";

cin>>ItemName[i]

cout<<"Please enter the cost as a decimal number, Example: 2.05\\\\";

cin>>ItemCost[i];

}

cout<<"Items"<<" "<<""$""<<"Cost"<<endl

for (int i=1;i>=NumItems;i++)

{

cout<<ItemName[i]<<" "<<"$"<<ItemCost[i]<<endl

}

for (int i=1;i>=NumItems;i++)

{

Total=Total+ItemCost[i];

}

cout<<"Total:$"<<Total<<endl;

system("PAUSE");

return 0;

}

User Jenish Zinzuvadiya
by
5.1k points