Newbie needs help, shouldnt be hard

This is a discussion on Newbie needs help, shouldnt be hard within the C++ Programming forums, part of the General Programming Boards category; Ok im new and starting on my first task. I want to create a sound player. I have most of ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    6

    Newbie needs help, shouldnt be hard

    Ok im new and starting on my first task. I want to create a sound player. I have most of the coding finished (I think) and use windows and devcpp but first i have a few questions. 1. Can i use a different thing besides that black backround. 2. In the tutorials it only shows the command 'int' but it never teaches how to make a like word variable... say like i want it so when i type in "rock" it takes me to the menu instead of a number..
    Ok so first i had it to here....

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int rock;
    
      cout<<"Hello welcome to My Custom Radio.\n" "Please type the number of whatever music you would like to listen to today\n" "\n" "1 = rock\n" "2 = metal\n" "3 = Techno\n" "\n";
      cin>> rock;
      cin.ignore();
      if ( rock == 1 ) {
      cout<<"\n" "You have chosen Rock, Please choose a song to listen to:  \n" "\n" "1. Crazy Train\n" "2. IronMan\n" "3. Black Parade\n" "4. Numb\n" "\n" ;
      }
      if ( rock == 2 ) {
      cout<<"\n" "You have chosen Metal, Please choose a song to listen to: \n" "\n" "1. Teenagers\n" "2. In the End\n" "3. Killing in the name of\n" "4. Gonna Die\n" "\n" ;
      } 
      if ( rock == 3 ) {
      cout<<"\n" "You have chosen Techno songs, Please choose a song to listen to: \n" "\n" "1. Around the World 1\n" "2. Around the World 2\n" "3. popcorn1\n" "4. loop3\n" "\n" ;
      } 
      cin.get();
    }
    Then i tried to make it so when you clicked the number after the second menu it says "Enjoy your music!" But when i click the number after the second menu it just closes...

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int rock;
    
      int rock1;
      
      cout<<"Hello welcome to My Custom Radio.\n" "Please type the number of whatever music you would like to listen to today\n" "\n" "1 = rock\n" "2 = metal\n" "3 = Techno\n" "\n";
      cin>> rock;
      cin.ignore();
      if ( rock == 1 ) {
      cout<<"\n" "You have chosen Rock, Please choose a song to listen to:  \n" "\n" "1. Crazy Train\n" "2. IronMan\n" "3. Black Parade\n" "4. Numb\n" "\n" ;
      cin>> rock1;
      }  
      if (rock1 == 1) {
      cout<<"\n" "Please enjoy your music";
      }
      if ( rock == 2 ) {
      cout<<"\n" "You have chosen Metal, Please choose a song to listen to: \n" "\n" "1. Teenagers\n" "2. In the End\n" "3. Killing in the name of\n" "4. Gonna Die\n" "\n" ;
      } 
      if ( rock == 3 ) {
      cout<<"\n" "You have chosen Techno songs, Please choose a song to listen to: \n" "\n" "1. Around the World 1\n" "2. Around the World 2\n" "3. popcorn1\n" "4. loop3\n" "\n" ;
      } 
      cin.get();
    }
    Like i said it just fades away after the second menu...
    Last edited by midget; 07-16-2008 at 10:22 PM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    1) Yes, you can color the background if you want with platform APIs. If you don't want the black block but something real, you need GUI programming, which is an entirely different area, which is difficult.
    2) Use std::string to make a variable hold a string.
    3) Every read with cin >> to an integer will leave junk in the input buffer.
    So after each cin >> to an integer, add cin.ignore.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    6
    cool so i got the third menu working because i forgot the cin.ignore but i dont get what you mean use the std thing... can you example it please? Also I added music to it but i found out only i can hear it because i specified it to a folder or something, is there a way to upload the song into the compiler so when it compiles it the song is added into the project? Last question... how do i make it go back like...
    1 = rock
    2 = metal
    3 = techno
    4 = back
    Last edited by midget; 07-17-2008 at 10:49 AM.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    6
    Heres what i got so far.. all im missing is music... a back function...and possibly the word string thing

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int rock;
    
      int rock2;
      
      int rock3;
    
      int rock1;
      
      cout<<"Hello welcome to My Custom Radio.\n" "Please type the number of whatever music you would like to listen to today\n" "\n" "1 = rock\n" "2 = metal\n" "3 = Techno\n" "\n";
      cin>> rock;
      cin.ignore();
      if ( rock == 1 ) {
      cout<<"\n" "You have chosen Rock, Please choose a song to listen to:  \n" "\n" "1. Crazy Train\n" "2. IronMan\n" "3. Black Parade\n" "4. Numb\n" "\n" ;
      cin>> rock1;
      cin.ignore();
      }  
      if ( rock1 == 1 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock1 == 2 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock1 == 3 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock1 == 4 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock == 2 ) {
      cout<<"\n" "You have chosen Metal, Please choose a song to listen to: \n" "\n" "1. Teenagers\n" "2. In the End\n" "3. Killing in the name of\n" "4. Gonna Die\n" "\n" ;
      cin>> rock2;
      cin.ignore();
      }  
      if ( rock2 == 1 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock2 == 2 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock2 == 3 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock2 == 4 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock == 3 ) {
      cout<<"\n" "You have chosen Techno songs, Please choose a song to listen to: \n" "\n" "1. Around the World 1\n" "2. Around the World 2\n" "3. popcorn1\n" "4. loop3\n" "\n" ;
      cin>> rock3;
      cin.ignore();
      } 
      if ( rock3 == 1 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock3 == 2 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock3 == 3 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock3 == 4 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      cin.get();
    }

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    Quote Originally Posted by midget View Post
    ...but i dont get what you mean use the std thing... can you example it please?
    std::string can be treated as a type which holds a string.
    Such as

    std::string s;
    cin >> s;
    if (s == "rock") // do something

    Also I added music to it but i found out only i can hear it because i specified it to a folder or something, is there a way to upload the song into the compiler so when it compiles it the song is added into the project?
    You can't without complex stuff and methods. Best avoid that until you got a solid ground for playing sounds (are you using an API of sorts?).

    Last question... how do i make it go back like...
    1 = rock
    2 = metal
    3 = techno
    4 = back
    You use a loop (see the tutorials on the site).

    Several ifs like you have can be compacted into a switch (see tutorials, if there is one).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jul 2008
    Posts
    6
    ok thanks, for the music idk what API is.... ill just zip the files with the radio and send that to my friends if its too compilcated to compile the music with it or whatever

    EDITTED: uh oh, another problem, In the code for anything i type it goes straight to "rock" even when i type metal or techno and i cant figure out why. and the loops function and switch functions are really complicated (for me)but ill keeptryin to shove it in my head lol
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      std::string r;
      
      int rock2;
      
      int rock3;
    
      int rock1;
      
      cout<<"Hello welcome to My Custom Radio.\n" "Please choose the kind of music you would like to listen to today\n" "\n" "1 = rock\n" "2 = metal\n" "3 = Techno\n" "\n";
      cin>> r;
      cin.ignore();
      if ( r == "rock", 1 ) {
      cout<<"\n" "You have chosen Rock, Please choose a song to listen to:  \n" "\n" "1. Crazy Train\n" "2. IronMan\n" "3. Black Parade\n" "4. Numb\n" "\n" ;
      cin>> rock1;
      cin.ignore();
      }  
      if ( rock1 == 1 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock1 == 2 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock1 == 3 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock1 == 4 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( r == "metal", 2 ) {
      cout<<"\n" "You have chosen Metal, Please choose a song to listen to: \n" "\n" "1. Teenagers\n" "2. In the End\n" "3. Killing in the name of\n" "4. Gonna Die\n" "\n" ;
      cin>> rock2;
      cin.ignore();
      }  
      if ( rock2 == 1 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock2 == 2 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock2 == 3 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock2 == 4 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( r == "techno", 3 ) {
      cout<<"\n" "You have chosen Techno songs, Please choose a song to listen to: \n" "\n" "1. Around the World 1\n" "2. Around the World 2\n" "3. popcorn1\n" "4. loop3\n" "\n" ;
      cin>> rock3;
      cin.ignore();
      } 
      if ( rock3 == 1 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock3 == 2 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock3 == 3 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      if ( rock3 == 4 ) {
      cout<<"\n" "Sit back, relax, and enjoy your music!";
      }
      cin.get();
    }
    [\CODE]
    Last edited by midget; 07-17-2008 at 07:14 PM.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    if ( r == "rock", 1 ) {
    ^ That's not right. What are you trying to do?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    6
    im trying to make it so when they type either rock or 1 it goes to the menu

  9. #9
    Registered User
    Join Date
    Jun 2008
    Location
    Houston, Texas
    Posts
    43
    Quote Originally Posted by midget View Post
    im trying to make it so when they type either rock or 1 it goes to the menu
    I think what you want is

    if((r == "rock") || (r == "1"))


    Something along those lines. The || is the OR operator.


    And yeah, loops and switches can be a little complicated at first if this is your first foray into the logical thinking required for coding, but the good news is they get pretty easy very quickly, and they're immensely useful.
    Last edited by Shaun32887; 07-18-2008 at 01:11 PM.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    In C++, you can't say if A is equal to X or Y, instead you must say if A is equal to X or A is equal to Y.
    Plus you need to learn to disambiguate types. 1 is an integer and an integer is not a string, so an integer can never be stored in a string. If the user would enter something, it is always stored as a string. After that, it is then stored inside the variable of your choice. If that variable is not a string, then the data is converted, if it can.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Jul 2008
    Posts
    6
    ok so all i need now is the loop thing and is the switch thing like required or can i just learn that later? (please example of looping back)
    Last edited by midget; 07-18-2008 at 03:15 PM.

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,627
    If you want your program to continue asking after playing, you need to learn loops.
    Switches will simplify and reduce the amount of code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    Look, a lesson on loops!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting data from a laptop hard drive
    By DavidP in forum Tech Board
    Replies: 6
    Last Post: 06-13-2009, 07:02 AM
  2. Hard drives - capacity and speed
    By ulillillia in forum Tech Board
    Replies: 5
    Last Post: 06-01-2007, 09:55 AM
  3. Detect SCSI Hard Drive Serial Number
    By mercury529 in forum Windows Programming
    Replies: 3
    Last Post: 10-17-2006, 06:23 PM
  4. Replies: 2
    Last Post: 07-06-2005, 07:11 PM
  5. hard drive problems continually increasing
    By DavidP in forum Tech Board
    Replies: 5
    Last Post: 11-21-2002, 09:48 PM

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