0

Sorry, still new to programming! Is it possible to have different types of variables in a for loop? In my example I'm wanting to use an int to represent the number and a char to represent the alphabet but I get many errors :/ I was hoping to get; " #1 in the alphabet is letter: a" " #2 in the alphabet is letter: b" etc ...

Thanks!

    for (int i{ 1 }, char alphabet{ 'a' }; int >= 26; i++, alphabet++ )
        {
            cout << "# " << i << " in the alphabet is letter: " << alphabet << endl;
        }
LPs
  • 15,295
  • 7
  • 27
  • 56
Kevin Nisbet
  • 121
  • 1
  • 8
  • 4
    Does this answer your question? [Is it possible to declare two variables of different types in a for loop?](https://stackoverflow.com/questions/2687392/is-it-possible-to-declare-two-variables-of-different-types-in-a-for-loop) – churill Dec 10 '19 at 14:25
  • There's also a type in your code: `int >= 26` should be `i <= 26` – Adrian Mole Dec 10 '19 at 14:26
  • For your particular case you can use a single variable `i` and the character is `'a'+i-1` – Kevin Dec 10 '19 at 14:30
  • Thanks for you responses! I noticed when i went back to VS i had the int >= rather than i <= . I got it working by having the alphabet variable declared before the loop the incremented it inside the loop – Kevin Nisbet Dec 10 '19 at 14:33

0 Answers0