Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. switch statement

switch statement

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aaron Knox
    wrote on last edited by
    #1

    Hi all, I'm still working on my switch statement program (from previous post)thanks to Joaquin my loop is working but for some reason my switch statements are not being activiated. I've included a portion of my code, the switch statements continue for each letter a state begins with (d,f,g,h,i,k,etc) Thanks, Aaron //this program is supposed to read state abbreviations from a file and output the corrosponding state to another file #include #include using namespace std; int main() { ifstream inAbrev("state abs.txt"); //opens the input file ofstream outState("states with abvs.txt"); //opens the output file char firstLetter, secondLetter; inAbrev >> firstLetter >> secondLetter; cout << firstLetter << secondLetter << endl; //just for me to see if anything is happening while(inAbrev) //read til the end of the file { inAbrev >> firstLetter >> secondLetter; cout << firstLetter << secondLetter << endl; switch (firstLetter) { case 'A' : switch (secondLetter) { case 'L' : outState << inAbrev << " is " << "Alabama" << endl; cout << inAbrev << " is " << "Alabama" << endl; //here i'm trying to see if anything is happening break; case 'K' : outState << inAbrev << " is " << "Alaska" << endl; break; case 'Z' : outState << inAbrev << " is " << "Arizona" << endl; break; case 'R' : outState << inAbrev << " is " << "Arkansas" << endl; break; } case 'C' : switch (secondLetter) { case 'A' : outState << inAbrev << " is " << "California" << endl; break; case 'O' : outState << inAbrev << " is " << "Colorado" << endl; break; case 'T' : outState << inAbrev << " is " << "Connecticut" << endl; break; } arrrgh

    Z D T 3 Replies Last reply
    0
    • A Aaron Knox

      Hi all, I'm still working on my switch statement program (from previous post)thanks to Joaquin my loop is working but for some reason my switch statements are not being activiated. I've included a portion of my code, the switch statements continue for each letter a state begins with (d,f,g,h,i,k,etc) Thanks, Aaron //this program is supposed to read state abbreviations from a file and output the corrosponding state to another file #include #include using namespace std; int main() { ifstream inAbrev("state abs.txt"); //opens the input file ofstream outState("states with abvs.txt"); //opens the output file char firstLetter, secondLetter; inAbrev >> firstLetter >> secondLetter; cout << firstLetter << secondLetter << endl; //just for me to see if anything is happening while(inAbrev) //read til the end of the file { inAbrev >> firstLetter >> secondLetter; cout << firstLetter << secondLetter << endl; switch (firstLetter) { case 'A' : switch (secondLetter) { case 'L' : outState << inAbrev << " is " << "Alabama" << endl; cout << inAbrev << " is " << "Alabama" << endl; //here i'm trying to see if anything is happening break; case 'K' : outState << inAbrev << " is " << "Alaska" << endl; break; case 'Z' : outState << inAbrev << " is " << "Arizona" << endl; break; case 'R' : outState << inAbrev << " is " << "Arkansas" << endl; break; } case 'C' : switch (secondLetter) { case 'A' : outState << inAbrev << " is " << "California" << endl; break; case 'O' : outState << inAbrev << " is " << "Colorado" << endl; break; case 'T' : outState << inAbrev << " is " << "Connecticut" << endl; break; } arrrgh

      Z Offline
      Z Offline
      Zdeslav Vojkovic
      wrote on last edited by
      #2

      set the breakpoint on "switch (firstLetter)" line and check the value of firstLetter and secondLetter variables to see what values exactly are in them.

      1 Reply Last reply
      0
      • A Aaron Knox

        Hi all, I'm still working on my switch statement program (from previous post)thanks to Joaquin my loop is working but for some reason my switch statements are not being activiated. I've included a portion of my code, the switch statements continue for each letter a state begins with (d,f,g,h,i,k,etc) Thanks, Aaron //this program is supposed to read state abbreviations from a file and output the corrosponding state to another file #include #include using namespace std; int main() { ifstream inAbrev("state abs.txt"); //opens the input file ofstream outState("states with abvs.txt"); //opens the output file char firstLetter, secondLetter; inAbrev >> firstLetter >> secondLetter; cout << firstLetter << secondLetter << endl; //just for me to see if anything is happening while(inAbrev) //read til the end of the file { inAbrev >> firstLetter >> secondLetter; cout << firstLetter << secondLetter << endl; switch (firstLetter) { case 'A' : switch (secondLetter) { case 'L' : outState << inAbrev << " is " << "Alabama" << endl; cout << inAbrev << " is " << "Alabama" << endl; //here i'm trying to see if anything is happening break; case 'K' : outState << inAbrev << " is " << "Alaska" << endl; break; case 'Z' : outState << inAbrev << " is " << "Arizona" << endl; break; case 'R' : outState << inAbrev << " is " << "Arkansas" << endl; break; } case 'C' : switch (secondLetter) { case 'A' : outState << inAbrev << " is " << "California" << endl; break; case 'O' : outState << inAbrev << " is " << "Colorado" << endl; break; case 'T' : outState << inAbrev << " is " << "Connecticut" << endl; break; } arrrgh

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        It appears as if nothing is happening because all of your output statements (cout and outState) in your switch statement are wrong. Your doing this: outState << inAbrev << " is " << "California" << endl; cout << inAbrev << " is " << "Alabama" << endl; What this is doing is trying to output the input filestream which, of course, will output nothing. If I read your homework right, you should be doing something like this: outState << firstLetter << secondLetter << " is Alabama" << endl; RageInTheMachine9532

        1 Reply Last reply
        0
        • A Aaron Knox

          Hi all, I'm still working on my switch statement program (from previous post)thanks to Joaquin my loop is working but for some reason my switch statements are not being activiated. I've included a portion of my code, the switch statements continue for each letter a state begins with (d,f,g,h,i,k,etc) Thanks, Aaron //this program is supposed to read state abbreviations from a file and output the corrosponding state to another file #include #include using namespace std; int main() { ifstream inAbrev("state abs.txt"); //opens the input file ofstream outState("states with abvs.txt"); //opens the output file char firstLetter, secondLetter; inAbrev >> firstLetter >> secondLetter; cout << firstLetter << secondLetter << endl; //just for me to see if anything is happening while(inAbrev) //read til the end of the file { inAbrev >> firstLetter >> secondLetter; cout << firstLetter << secondLetter << endl; switch (firstLetter) { case 'A' : switch (secondLetter) { case 'L' : outState << inAbrev << " is " << "Alabama" << endl; cout << inAbrev << " is " << "Alabama" << endl; //here i'm trying to see if anything is happening break; case 'K' : outState << inAbrev << " is " << "Alaska" << endl; break; case 'Z' : outState << inAbrev << " is " << "Arizona" << endl; break; case 'R' : outState << inAbrev << " is " << "Arkansas" << endl; break; } case 'C' : switch (secondLetter) { case 'A' : outState << inAbrev << " is " << "California" << endl; break; case 'O' : outState << inAbrev << " is " << "Colorado" << endl; break; case 'T' : outState << inAbrev << " is " << "Connecticut" << endl; break; } arrrgh

          T Offline
          T Offline
          Toni78
          wrote on last edited by
          #4

          Yep RageInTheMachine is right. none

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups