Need help with if/else and switch commands please

This is a discussion on Need help with if/else and switch commands please within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm doing a problem for my C++ programming class online, and having problems, the error isn't a compiling problem, ...

  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,185
    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,189
    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++.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    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, 08: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, 05:40 PM
  4. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM

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