Switch statement
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 4 of 4
  1. #1
    teishu Guest

    Switch statement

    hi, what wrong with this ?

    Code:
    /***************************************************************************
     *   Copyright (C) 2007 by Jason Underhill   *
     *   jay.underhill@gmail.com   *
     *                                                                         *
     *   This program is free software; you can redistribute it and/or modify  *
     *   it under the terms of the GNU General Public License as published by  *
     *   the Free Software Foundation; either version 2 of the License, or     *
     *   (at your option) any later version.                                   *
     *                                                                         *
     *   This program is distributed in the hope that it will be useful,       *
     *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
     *   GNU General Public License for more details.                          *
     *                                                                         *
     *   You should have received a copy of the GNU General Public License     *
     *   along with this program; if not, write to the                         *
     *   Free Software Foundation, Inc.,                                       *
     *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
     ***************************************************************************/
    
    
    #ifdef HAVE_CONFIG_H
    #include <config.h>
    #endif
    
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    int menu = 0;
    
    while(1)
    {
    menu = 0;
    	switch(menu){
    		case 1:
    			cout << "Case 1" << endl;
    		break;
    
    		case 2:
    			cout << "Case 2" << endl;
    		break;
    
    		case 3:
    			cout << "Case 3" << endl;
    		break;
    
    		default:
    			cout << "CPU Heater" << endl;
    			cout << "Please select an option from the menu." << endl;
    			cout << "1. Start Heating" << endl;
    			cout << "2. About" << endl;
    			cout << "3. Exit" << endl;
    			cin >> menu;
    		}
    }
    
      return EXIT_SUCCESS;
    }
    i know its not going to do what it should yet, just trying to get the switch working.

  2. #2
    Join Date
    Dec 2005
    Location
    Arkansas
    Age
    29
    Posts
    1,160
    You have menu reset to 0 each time it loops again. Take that line out and it should work now. Short of it's going to print one of the cases you select indefinitely.
    Laptop: Lenovo ThinkPad T420, CPU: Intel Core i5 520M, Ram: 8GB DDR3, Hard Drive: 320GB, Graphics: Intel HD, OS: Windows 7 / Arch Linux x86_64
    Desktop: Motherboard: ASRock Fatal1ty AB350 Gaming K4, CPU: AMD Ryzen 3 1200, RAM: 8GB DDR4, Storage: Samsung 850 Pro 256GB, Graphics: Asus Radeon RX 550 4GB, OS: Arch Linux x86_64

  3. #3
    teishu Guest
    Cheers m8 sorted.. didn't realise that was ther hehe

  4. #4
    Join Date
    Dec 2005
    Location
    Arkansas
    Age
    29
    Posts
    1,160
    I had to indent it properly before I could spot that. If you make your code easier to read you'll be able to spot bugs quickly.
    Laptop: Lenovo ThinkPad T420, CPU: Intel Core i5 520M, Ram: 8GB DDR3, Hard Drive: 320GB, Graphics: Intel HD, OS: Windows 7 / Arch Linux x86_64
    Desktop: Motherboard: ASRock Fatal1ty AB350 Gaming K4, CPU: AMD Ryzen 3 1200, RAM: 8GB DDR4, Storage: Samsung 850 Pro 256GB, Graphics: Asus Radeon RX 550 4GB, OS: Arch Linux x86_64

Similar Threads

  1. Insert Statement from mySQL
    By AndreasMet in forum Using Fedora
    Replies: 1
    Last Post: 26th November 2006, 11:39 AM
  2. if statement in bash
    By Adesso in forum Programming & Packaging
    Replies: 1
    Last Post: 1st September 2006, 03:33 PM
  3. bash if statement going bunk
    By jim in forum Programming & Packaging
    Replies: 9
    Last Post: 27th January 2006, 04:55 AM
  4. If statement not working...! What is going wrong here?
    By savage in forum Programming & Packaging
    Replies: 2
    Last Post: 30th December 2005, 03:19 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •