Enum

This is a discussion on Enum within the C++ Programming forums, part of the General Programming Boards category; How should i go to get the numbers in the Frequency[] array passing by the Song[] array? Maybe im not ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    856

    Enum

    How should i go to get the numbers in the Frequency[] array passing by the Song[] array?
    Maybe im not using the right method at all.


    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        enum Note {B5,As5,A5,Gs5,G5,Fs5,F5,E5,Ds5,D5,Cs5,C5,};
    
        double Frequency[] = {
       10,20,30,40,50,60,70,80,90,100,110,120,
        };
    
        char Song[] = {Ds5,Gs5,Gs5,F5,Ds5,Gs5,Ds5,Ds5,F5,};
    
        for(x=0; x<=9; x++) cout <<  Song[Note(Frequency[x])];
    
        return 0;
    }
    Last edited by Ducky; 03-21-2010 at 03:26 AM.
    Compiler MSVC++ 2013 with Code::Blocks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,641
    What do you mean by "numbers in the Frequency[] array passing by the Song[] array"?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    856
    I mean the values in the Frequency[] array passing by the Song[] array.

    Like if i pass Song[3] which is = Gs5 and the 4th member of enum Notes, i want to get 40, which is the also the 4th member of Frequency[].

    Maybe i shouldnt use enum by the way.
    Last edited by Ducky; 03-21-2010 at 03:43 AM.
    Compiler MSVC++ 2013 with Code::Blocks.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,641
    Oh, now I understand. Since you want to print elements of the Frequency array, it is obvious that you want an expression of the form Frequency[index]. Now, index must correspond to an enumerator value, presumably obtained from the song array. Therefore, the expression should be Frequency[Song[x]].

    A few other things to note: the enum should not be declared with a trailing comma. Song should be an array of Note, not char. Your loop condition is not correct.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    856
    Brilliant!

    Thats exactly what i wanted.
    I corrected everything and it works great.

    Thank you very much Laserlight!
    Compiler MSVC++ 2013 with Code::Blocks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic question on enum
    By MasterM in forum C++ Programming
    Replies: 2
    Last Post: 06-12-2009, 09:16 PM
  2. enum [tag] [: type] Is this non-standard?
    By HyperShadow in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2007, 09:29 PM
  3. enum switchcase and windows message q
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 11-27-2006, 12:16 PM
  4. Conflicting enum issue
    By 7force in forum C Programming
    Replies: 1
    Last Post: 07-05-2006, 03:51 AM
  5. Switch case and enum help
    By SomeCrazyGuy in forum C++ Programming
    Replies: 9
    Last Post: 04-21-2005, 08:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21