Write the following program in c++.
Combine your first and second name and pick only the first five characters of your name for
the project.
i. Declare an array named name1 and put all the first five characters into it.
ii. Write a for loop with an if condition that will find and output the index value of a
searched character in the array. Let the program be such that the user will input the
character being searched for.

Respuesta :

For loops in computer programs are used to perform repetitive operations, while if conditions are used to make decisions

The program in C++, where comments are used to explain each line is as follows:

#include <iostream>

using namespace std;

int main(){

   //This initializes the array

   char name1[] = {'R','O','Y','A','L'};

   //This declares a character variable

   char searchedChar;

   //This gets input for the character

   cin>>searchedChar;

   //This iterates through the array

   for(int i = 0; i<5;i++){

       //If the searched character equals the current array element

       if (searchedChar == name1[i]){

           //This prints the index of the element

           cout<<i;

       }

   }

   return 0;

}

Read more about loops and conditions at:

https://brainly.com/question/18750495

ACCESS MORE