If you have and array, for example char potatoes[100], and you know that in the n number of the array and only that number has the element G, can you know n?
If I am understanding your question correctly, I've wondered the same thing myself and I'm pretty certain there is no better way besides using a loop. Someone can correct me if I'm wrong, but to my understanding you are able to get the value of an array at a particular index with one operation (i.e. potatoes[5]), but not the other way around: using only one operation to get the particular index of an array when given the value.
And a few tips that I think would clean up your code a bit: you output the value of potatoes[counting] when you mentioned that you were looking for the index, which is just the value of counting. Based on your code, the value you output will always be 'G', or the last element in the array if there is no G.
You also don't need the counting variable. You can loop by incrementing x and then once you find the value you're looking for, you can output x right in the conditional statement, call the break, and then you're done.
There's no need to increment a variable until you find the one you want. Just remember where it was found, if it was found. This allows you to use -1 to mean not found, which is a common convention.
(With your approach you should check that counting is less than the array size before using it to access the array element.)
// this code needs a C++11+ compiler
#include <iostream>
#include <algorithm>
#include <iterator>
// not using using namespace std; here
int main()
{
char potatoes[100] = {0}; // zero all elements
potatoes[42] = 'G';
auto iter_beg = std::begin(potatoes);
auto iter_end = std::end(potatoes);
// find uses a loop for you
auto iter = std::find(iter_beg, iter_end, 'G');
if(iter_end == iter)
std::cout << "not found" << std::endl;
else
std::cout << "found at " << std::distance(iter_beg, iter) << std::endl;
return 0;
}