Answer to Question #155075 in C++ for LEEYAH

Question #155075

Write a code to create an array with the following elements a,b,c,d,e,f,g,h,i,j,k. Test if the array contain a specific character provided by the user. If found display the index number else display "item not found."


1
Expert's answer
2021-01-12T10:13:17-0500
#include <iostream>

using namespace std;

int main()
{
	char a[11];
	for (int i = 0; i < 11; i++)
		a[i] = 'a' + i;	
	char s; 
	cin >> s;
	int flag = -1;
	for (int i = 0; i < 11; i++)
		if (a[i] == s)
			flag = i;
	if (flag == -1)
		cout << "item not found";
	else
		cout << flag;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog