Write your question here.
Does anyone know how to check if a string array contains a string?
can i use an if ststement.
Thanks.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string order[10];
double total = 0.00;
for(int purchases = 0; purchases <= 1; purchases++)
{
cout << "Latte\t$2.50\n" << "Decaf\t$1.00\n" << "Mocha\t$3.00\n"
<< "Expresso$3.00\n";
cout << "What would you like to order?\n";
cin >> order[purchases];
}
for(int h = 0; h <= 1; h++)
{
if(latee == order[h]);
{
total = total + 2.50;
cout << "it works\n";
}
}
for(int i = 1; i <= 2; i++)
{
cout << order[i] << endl;
}
cout << "Your total is $" << total << endl;
Note, that the for-loop doesn't terminate just because it's found the string we're looking for. All it does once our desired string is found is set found to true. If there were more string elements in our array, the for loop would continue searching the array, comparing elements against our find_string even though it was already found.