writing a program for a grocery list for Ctt where the user can add five items a
ID: 3885722 • Letter: W
Question
writing a program for a grocery list for Ctt where the user can add five items and an option to add how many then give a total at the end . im a bit stuck on this one
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Welcome to Neeky's Bulk Hair!" << endl;
cout << "Who do I have the pleasure of speaking with today?" << endl;
string Name;
cout << "Enter name: " << endl;
cin >> Name;
string Items;
cout << "What items will you be purchasing today: " << Name << endl;
cin >> Items;
cout << "Those items are available for you today!" << Name << endl;
string Price;
cout << "How much is each item" << endl;
cin >> Price;
string Item1;
cout << "Enter price for item1: " << endl;
cin >> Item1;
string Quantity;
cout << "Quantity for this item: " << endl;
cin >> Quantity;
string Item2;
cout << "How much is item2: " << endl;
cin >> Item2;
string Quantity;
cout << "Quantity for this item: " << endl;
cin >> Quantity;
string Item3;
cout << "How much is item3: " << endl;
cin >> Item3;
string Quantity;
cout << "Quantity for this item: " << endl;
cin >> Quantity;
string Item4;
cout << "How much is item4 : " << endl;
cin >> Item4;
string Quantity;
cout << "Quantity for this item: " << endl;
cin >> Quantity;
string Item5;
cout << "How much is item5: " << endl;
cin >> Item5;
string Quantity;
cout << "Quantity for this item: " << endl;
cin >> Quantity;
cout << "Item1 + Item2 + Item3 + Item4 + Item5 = " << Item1 + Item2 + Item3 + Item4 + Item5 << endl;
system("Pause");
return 0;
}
Explanation / Answer
Explanation
Hey Buddy, it is problem with the type you used which is string. When we want to take input as a number, we need to use integer. Added total as well.
Code
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Welcome to Neeky's Bulk Hair!" << endl;
cout << "Who do I have the pleasure of speaking with today?" << endl;
string Name;
cout << "Enter name: ";
cin >> Name;
string Items;
cout << "What items will you be purchasing today " << Name << ": ";
cin >> Items;
cout << "Those items are available for you today!" << Name << endl << endl;
int Item1;
cout << "Enter price for item1: ";
cin >> Item1;
int Quantity1;
cout << "Quantity for this item: ";
cin >> Quantity1;
int Item2;
cout << "How much is item2: ";
cin >> Item2;
int Quantity2;
cout << "Quantity for this item: ";
cin >> Quantity2;
int Item3;
cout << "How much is item3: ";
cin >> Item3;
int Quantity3;
cout << "Quantity for this item: ";
cin >> Quantity3;
int Item4;
cout << "How much is item4 : ";
cin >> Item4;
int Quantity4;
cout << "Quantity for this item: ";
cin >> Quantity4;
int Item5;
cout << "How much is item5: ";
cin >> Item5;
int Quantity5;
cout << "Quantity for this item: ";
cin >> Quantity5;
cout << "Item1 + Item2 + Item3 + Item4 + Item5 = " << Item1 + Item2 + Item3 + Item4 + Item5 << endl;
cout << "Total = " << Item1*Quantity1 + Item2*Quantity2 + Item3*Quantity3 + Item4*Quantity4 + Item5*Quantity5 << endl;
system("Pause");
return 0;
}
Please rate it if you are good with it. Happy learning!
Explanation
Hey Buddy, it is problem with the type you used which is string. When we want to take input as a number, we need to use integer. Added total as well.
Code
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Welcome to Neeky's Bulk Hair!" << endl;
cout << "Who do I have the pleasure of speaking with today?" << endl;
string Name;
cout << "Enter name: ";
cin >> Name;
string Items;
cout << "What items will you be purchasing today " << Name << ": ";
cin >> Items;
cout << "Those items are available for you today!" << Name << endl << endl;
int Item1;
cout << "Enter price for item1: ";
cin >> Item1;
int Quantity1;
cout << "Quantity for this item: ";
cin >> Quantity1;
int Item2;
cout << "How much is item2: ";
cin >> Item2;
int Quantity2;
cout << "Quantity for this item: ";
cin >> Quantity2;
int Item3;
cout << "How much is item3: ";
cin >> Item3;
int Quantity3;
cout << "Quantity for this item: ";
cin >> Quantity3;
int Item4;
cout << "How much is item4 : ";
cin >> Item4;
int Quantity4;
cout << "Quantity for this item: ";
cin >> Quantity4;
int Item5;
cout << "How much is item5: ";
cin >> Item5;
int Quantity5;
cout << "Quantity for this item: ";
cin >> Quantity5;
cout << "Item1 + Item2 + Item3 + Item4 + Item5 = " << Item1 + Item2 + Item3 + Item4 + Item5 << endl;
cout << "Total = " << Item1*Quantity1 + Item2*Quantity2 + Item3*Quantity3 + Item4*Quantity4 + Item5*Quantity5 << endl;
system("Pause");
return 0;
}
Output Welcome to Neeky's Bulk Hair! Who do I have the pleasure of speaking with today? Enter name: Sindhu What items will you be purchasing today Sindhu: Juice Those items are available for you today!Sindhu Enter price for item1: 1 Quantity for this item: 2 How much is item2: 2 Quantity for this item: 4 How much is item3: 1 Quantity for this item: 2 How much is item4 : 2 Quantity for this item: 4 How much is item5: 1 Quantity for this item: 2 Item1 + Item2 + Item3 + Item4 + Item5 = 7 Total = 22
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.