Hi im currently doing some work with arrays and ive been working on this program.
The goal is a user can add up to three products. Each product will have a name, model number and price. Once all is entered a list will pop out showing all the products with their respective model number and price. my part1 of the code allows the user to do the inputs and part shows the output.
#include <iostream>
using namespace std;
char product[10][100];
char model[10][100];
char price[10][100];
int first();
int second();
int main()
{
first();
second();
return 0;
}
int first()
{
for (int i = 0; i < 3; i++)
{
cout << "Please enter up to ten products: ";
cin >> product[i];
cout << "Please enter up to ten model numbers: ";
cin >> model[i];
cout << "Please enter the prices: ";
cin >> price[i];
}
}
int second()
{
cout<<"\n";
cout<<product[0]<<" "<<model[0]<<" "<<price[0]<<" "<<endl;
cout<<product[1]<<" "<<model[1]<<" "<<price[1]<<" "<<endl;
cout<<product[2]<<" "<<model[2]<<" "<<price[2]<<" "<<endl;
system("pause");
return 0;
system("exit");
}
This is all working fantastic however, what if a user wanted to end the loop early?
I want a way so that when prompted to enter the product name, the user can type "quit" and the loop will break.
Example. a User will enter one product with its model number and price but when asked again another product, he will type "quit". The loop will end and the information about his one and only product will be displayed.
ive tried using if statements and while loops but i have no idea. any help is appreciated. if you wish to see these failed codes i can put them up also.
any help is much appreciated