Thread: Need help with if/else and switch commands please

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    6

    Need help with if/else and switch commands please

    Hello, I'm doing a problem for my C++ programming class online, and having problems, the error isn't a compiling problem, its when I enter the information into the program, even though I'm using if/else statements, the outcome still is referring to the switch cases witin the first if/else statement, even if I enter 2 or 3 for the offNum

    Code:
    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main()
    {
        int offNum = 0;
        int actNum = 0;
    
        cout << "Enter Office Number (1/2/3): ";
        cin >> offNum;
        cout << "Enter Activity number (1/2/3/4): ";
        cin >> actNum;
        
        if (offNum = 1)
                   switch (actNum)
                   {
                          case 1: cout << "Raleigh: Making a new appointment" << endl;
                          break;
                          case 2: cout << "Raleigh: Rescheduling an appointment" << endl;
                          break;
                          case 3: cout << "Raleigh: Billing questions" << endl;
                          break;
                          case 4: cout << "Raleigh: Talking to a nurse" << endl;
                   }                   
                          else
                          {
                              if (offNum = 2)
                                    switch (actNum)
                                    {
                                           case 1: cout << "Durham: Making a new appointment" << endl;
                                           break;
                                           case 2: cout << "Durham: Rescheduling an appointment" << endl;
                                           break;
                                           case 3: cout << "Durham: Billing questions" << endl;
                                           break;
                                           case 4: cout << "Durham: Talking to a nurse" << endl;
                                    }       
                                           else
                                           {
                                               if (offNum = 3)
                                                          switch (actNum)
                                                          {
                                                                 case 1: cout << "Chapel Hill: making a new appointment" << endl;
                                                                 break;
                                                                 case 2: cout << "Chapel Hill: Rescheduling an appointment" << endl;
                                                                 break;
                                                                 case 3: cout << "Chapel Hill: Billing questions" << endl;
                                                                 break;
                                                                 case 4: cout << "Chapel Hill: Talking to a nurse" << endl;
                                                          }
                                                                 else
                                                                 cout << "Input Error" << endl;
                                           }
                          }
                          system("pause");
                          return 0;
    }
    If you want to see the actual problem itself in text, just reply asking, I'll be sure to post it immediately, thanks in advance

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    offnum = 1
    and
    offnum == 1
    are not the same thing.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    6
    Ahhh, no wonder.... I can't believe I forgot that, see, this is the problem with set-pace classes, cause I have to go a week w/o programming and forget stuff, thanks, I wish I could just have a self paced course and do it all at one time XD

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by masterofwar14 View Post
    Ahhh, no wonder.... I can't believe I forgot that, see, this is the problem with set-pace classes, cause I have to go a week w/o programming and forget stuff, thanks, I wish I could just have a self paced course and do it all at one time XD
    I wonder if the local community college would let me teach a class on Intro to computer programming with C/C++.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Your indentation is wrong btw. Each 'else' statement should line up vertically with the preceeding 'if'.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  3. Switch
    By cogeek in forum C Programming
    Replies: 4
    Last Post: 12-23-2004, 06:40 PM
  4. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM