Help! Anybody know C++?

audiobliss
audiobliss Posts: 12,518
edited September 2007 in The Clubhouse
Ok, I'm having to write a program in my C++ class and I have to submit it online by midnight...an hour and a half from now! Any help with finding my error(s) would be GREATLY appreciated!!

Here's the problem:

Write a program that asks the user to enter one of the following state abbreviations: NC, SC, GA, FL, or AL. The program should then display the name of the state that corresponds with the abbreviation entered.

Ok, so here's the code I've written, that's throwing a TON of errors!
#include "stdafx.h"
#include< iostream >
#include< string >
using namespace std;

int main()
{
string abb;

//Get input from user
cout << "Enter a two-character abbreviation for North Carolina, " << endl;
cout << "South Carolina, Georgia, Florida, or Alabama.";
cin >> abb;
cout << "\n\n";

//Determine which state was entered and display result
if (abb == 'nc' || abb == 'NC')
cout << "The state you entered is North Carolina!";
else if (abb == 'sc' || abb == 'SC')
cout << "The state you entered is South Carolina!";
else if (abb == 'ga' || abb == 'GA')
cout << "The state you entered is Georgia!";
else if (abb == 'fl' || abb == 'FL')
cout << "The state you entered is Florida!";
else if (abb == 'al' || abb == 'AL')
cout << "The state you entered is Alabama!";
else
{
cout << "Unexpected input provided. Please run program again ";
cout << "using proper input.";
}

//Create spacing
cout << "\n\n";

//Pause so user can view output
system("pause");

return 0;
}

What's wrong?!
Jstas wrote: »
Simple question. If you had a cool million bucks, what would you do with it?
Wonder WTF happened to the rest of my money.
In Use
PS3, Yamaha CDR-HD1300, Plex, Amazon Fire TV Gen 2
Pioneer Elite VSX-52, Parasound HCA-1000A
Klipsch RF-82ii, RC-62ii, RS-42ii, RW-10d
Epson 8700UB

In Storage
[Home Audio]
Rotel RCD-02, Yamaha KX-W900U, Sony ST-S500ES, Denon DP-7F
Pro-Ject Phono Box MKII, Parasound P/HP-850, ASL Wave 20 monoblocks
Klipsch RF-35, RB-51ii

[Car Audio]
Pioneer Premier DEH-P860MP, Memphis 16-MCA3004, Boston Acoustic RC520
Post edited by audiobliss on

Comments

  • audiobliss
    audiobliss Posts: 12,518
    edited September 2007
    Hahaha, I fixed it, with some help from baggedlancer - thanks!

    In my if statements, the abbreviations are strings...and so need DOUBLE quotation marks instead of the single quotes.

    Thanks, though!
    Jstas wrote: »
    Simple question. If you had a cool million bucks, what would you do with it?
    Wonder WTF happened to the rest of my money.
    In Use
    PS3, Yamaha CDR-HD1300, Plex, Amazon Fire TV Gen 2
    Pioneer Elite VSX-52, Parasound HCA-1000A
    Klipsch RF-82ii, RC-62ii, RS-42ii, RW-10d
    Epson 8700UB

    In Storage
    [Home Audio]
    Rotel RCD-02, Yamaha KX-W900U, Sony ST-S500ES, Denon DP-7F
    Pro-Ject Phono Box MKII, Parasound P/HP-850, ASL Wave 20 monoblocks
    Klipsch RF-35, RB-51ii

    [Car Audio]
    Pioneer Premier DEH-P860MP, Memphis 16-MCA3004, Boston Acoustic RC520
  • Serendipity
    Serendipity Posts: 6,975
    edited September 2007
    You need to replace the quotation marks with double quotation marks.

    Which compiler are you using?

    I'd recommend indenting in an organized fashion, makes the code much easier to read.
    polkaudio RT35 Bookshelves
    polkaudio 255c-RT Inwalls
    polkaudio DSWPro550WI
    polkaudio XRT12 XM Tuner
    polkaudio RM6750 5.1

    Front projection, 2 channel, car audio... life is good!
  • BaggedLancer
    BaggedLancer Posts: 6,371
    edited September 2007
    "Bows"


    Thank you, Thank you


    haha, had to break out my C++ book that hasn't been off the shelf in almost 4 years.......and immediately returned it to the shelf where it will rest for many years to come
  • Serendipity
    Serendipity Posts: 6,975
    edited September 2007
    oops, realized you figured it out already.
    polkaudio RT35 Bookshelves
    polkaudio 255c-RT Inwalls
    polkaudio DSWPro550WI
    polkaudio XRT12 XM Tuner
    polkaudio RM6750 5.1

    Front projection, 2 channel, car audio... life is good!
  • audiobliss
    audiobliss Posts: 12,518
    edited September 2007
    Yeah, I have it nicely indented in MS' Visual C++ 2005 Express Edition; I just lost the formatting copying it into the post.
    Jstas wrote: »
    Simple question. If you had a cool million bucks, what would you do with it?
    Wonder WTF happened to the rest of my money.
    In Use
    PS3, Yamaha CDR-HD1300, Plex, Amazon Fire TV Gen 2
    Pioneer Elite VSX-52, Parasound HCA-1000A
    Klipsch RF-82ii, RC-62ii, RS-42ii, RW-10d
    Epson 8700UB

    In Storage
    [Home Audio]
    Rotel RCD-02, Yamaha KX-W900U, Sony ST-S500ES, Denon DP-7F
    Pro-Ject Phono Box MKII, Parasound P/HP-850, ASL Wave 20 monoblocks
    Klipsch RF-35, RB-51ii

    [Car Audio]
    Pioneer Premier DEH-P860MP, Memphis 16-MCA3004, Boston Acoustic RC520
  • Serendipity
    Serendipity Posts: 6,975
    edited September 2007
    Sure, at first I thought there were no indents in the code.

    We need a Homework Help forum :)

    Or we can just post in the Clubhouse :)
    polkaudio RT35 Bookshelves
    polkaudio 255c-RT Inwalls
    polkaudio DSWPro550WI
    polkaudio XRT12 XM Tuner
    polkaudio RM6750 5.1

    Front projection, 2 channel, car audio... life is good!
  • audiobliss
    audiobliss Posts: 12,518
    edited September 2007
    Hahaha. Yeah. This IS our homework help forum!
    Jstas wrote: »
    Simple question. If you had a cool million bucks, what would you do with it?
    Wonder WTF happened to the rest of my money.
    In Use
    PS3, Yamaha CDR-HD1300, Plex, Amazon Fire TV Gen 2
    Pioneer Elite VSX-52, Parasound HCA-1000A
    Klipsch RF-82ii, RC-62ii, RS-42ii, RW-10d
    Epson 8700UB

    In Storage
    [Home Audio]
    Rotel RCD-02, Yamaha KX-W900U, Sony ST-S500ES, Denon DP-7F
    Pro-Ject Phono Box MKII, Parasound P/HP-850, ASL Wave 20 monoblocks
    Klipsch RF-35, RB-51ii

    [Car Audio]
    Pioneer Premier DEH-P860MP, Memphis 16-MCA3004, Boston Acoustic RC520
  • Serendipity
    Serendipity Posts: 6,975
    edited September 2007
    I'm doing homework right now and this forum proved to be a great help.

    Some examples:
    http://www.polkaudio.com/forums/showthread.php?t=51407&highlight=math+problem
    polkaudio RT35 Bookshelves
    polkaudio 255c-RT Inwalls
    polkaudio DSWPro550WI
    polkaudio XRT12 XM Tuner
    polkaudio RM6750 5.1

    Front projection, 2 channel, car audio... life is good!
  • audiobliss
    audiobliss Posts: 12,518
    edited September 2007
    Yeah, this forum's been a great source of 'homework' help for me, too. Just a few examples:

    Liberty Basic programming problem

    Question about Maple

    Calc 1 problem (chain rule)

    Calc problem I appearantly never figured out...haha
    Jstas wrote: »
    Simple question. If you had a cool million bucks, what would you do with it?
    Wonder WTF happened to the rest of my money.
    In Use
    PS3, Yamaha CDR-HD1300, Plex, Amazon Fire TV Gen 2
    Pioneer Elite VSX-52, Parasound HCA-1000A
    Klipsch RF-82ii, RC-62ii, RS-42ii, RW-10d
    Epson 8700UB

    In Storage
    [Home Audio]
    Rotel RCD-02, Yamaha KX-W900U, Sony ST-S500ES, Denon DP-7F
    Pro-Ject Phono Box MKII, Parasound P/HP-850, ASL Wave 20 monoblocks
    Klipsch RF-35, RB-51ii

    [Car Audio]
    Pioneer Premier DEH-P860MP, Memphis 16-MCA3004, Boston Acoustic RC520
  • Systems
    Systems Posts: 14,873
    edited September 2007
    Takes me back to college lol. Only thing we had to compile C and c++ was a unix prompts and Vi editor :):):)

    The fancy compilers were just coming out (Borland and such).

    I core dumped PSU's university so many damn times, their sys admin hated me.
    Testing
    Testing
    Testing
  • Systems
    Systems Posts: 14,873
    edited September 2007
    Heres a good one from 96!

    //FILE: as4

    //
    //EXPLANATION: This program takes integer values of off a file called "numdata" and stores
    // them into an array. The program will retrieve 1000, 2500, or 6000 integers
    // from the file. IT then runs the array through a given sort algorithm that the
    // user will choose. These sorts are select, bubble, quick 1, quick 2, insertion, and
    // merge. These sorts, sort the array and time how long it takes to sort it
    // completely and returns the time in seconds to the user.
    //
    //INPUT: This program takes as input one file full of integers only called "numdata".
    // This program also takes a few menu selections from the user in integer form.
    //
    //OUTPUT: This program outputs to the user 2 menus which the user must make a choice. // This program also outputs to the user the amount of time it took the given sort // algorithm to sort an array of integers.
    //Headers.
    #include <time.h>
    #include <fstream.h>
    #include <ctype.h>
    #include <string.h>
    #include "slctsort.cpp"
    #include "bubsort2.cpp"
    #include "qsort1.cpp"
    #include "qsort2.cpp"



    //Global function declerations.
    void get_int (ifstream & in, int & integer);
    void Mergesort (int [], int & , int &);
    void Merge_s (int [], int &, int &,
    int & , int &);
    void Insertsort (int [], int &);



    //Global constants
    const int max_array_size = 6001;
    const int field_size = 102;



    main ()
    {
    //Local Variables.
    ifstream in;
    static int ints [max_array_size]; //Array containing word.
    int menu_n; //Represents menu selection.
    int menu_sort; //Represents menu selection.
    int i = 0; //index variable.
    int integer; //integer holding variable.
    int max_array = 0; //maximum size of array elements.
    int size = 0; //Represents size of the array.
    time_t * getter = 0; //Timer variable.
    long int timer = 0; //Timer variable.
    long int timer_2 = 0; //Timer variable.
    long int t_time = 0; //Timer variable.

    //Users selection menu for sorts
    cout << endl << "Please enter the sort that you would like"
    << " to use:" << endl
    << "1) Select Sort\n"
    << "2) Bubble Sort\n"
    << "3) Quick Sort 1\n"
    << "4) Quick Sort 2\n"
    << "5) Insertion Sort\n"
    << "6) Merge Sort\n"
    << "Please choose a number-->";
    cin >> menu_sort;

    //Users selection number for array sizes.
    cout << endl << "Please choose the maximum n:" << endl
    << "1) n = 1000\n"
    << "2) n = 2500 integer\n"
    << "3) n = 2500 real\n"
    << "4) n = 6000\n"
    << "please choose a number-->";
    cin >> menu_n;

    //If structure for setting of maximum array size to be sorted.
    if (menu_n == 1)
    max_array = 1000;
    else if (menu_n == 2 || menu_n == 3)
    max_array = 2500;
    else
    max_array = 6000;

    //Open file for reading.
    in.open ("numdata");

    //while loop for the retreiving and storing of an integer.
    while (i <= max_array)
    {
    //Function call that gets an int.
    get_int (in, integer);
    //Put the integer in the (i)th element of the array.
    ints = integer;
    ++size;
    ++i;
    }
    //Last element of the array set to NULL
    ints [i-1] = '\0';
    //Fix size.
    size = size - 1;

    //Close the file for reading.
    in.close ();

    //Get first time.
    timer = time (getter);

    //If structure for the calling of choosen sort.
    if ( menu_sort == 1)
    Sort (ints, size);
    else if (menu_sort == 2)
    B_Sort (ints, size);
    else if (menu_sort == 3)
    Quicksort (ints, 0, (size - 1));
    else if (menu_sort == 4)
    Quicksort_2 (ints, 0, (size - 1));
    else if (menu_sort == 5)
    Insertsort (ints, (size - 1));
    else if (menu_sort == 6)
    Mergesort (ints, 0, (size - 1));

    //Get second time.
    timer_2 = time (getter);
    //get total seconds elapsed.
    t_time = timer_2 - timer;

    //Output seconds to user.
    cout << "\nTotal seconds that this sort took was-->"
    << t_time << endl;

    //END PROGRAM.
    cout << "\nEND PROGRAM!!!" << endl;
    }



    //FUNCTION: Mergesort
    //EXPLANATION: This function receives an array from it's caller full of integers and two integers
    // that represent the beginning and end of the array elements. This function sorts
    // the array by the merge sort method. And returns the sorted array.
    //
    //INPUT: This function receives as input from it's caller an array of integers. It also
    // receives as input two pass by reference integer that represent the beginning and
    // end of the array elements.
    //
    //OUTPUT: This function outputs to it's caller an array of integers sorted in acceding
    // order.

    void Mergesort (int ints [], int & first , int & last)
    {
    int mid; //The int value between first and last.

    //IF loop for recursion.
    if (first < last)
    {
    //Get mid point.
    mid = ((first + last)/2);
    //Recursion function calls.
    Mergesort (ints, first, mid);
    Mergesort (ints, (mid + 1), last);
    //Merge_s function call.
    Merge_s (ints, first, mid, (mid + 1), last);
    }
    }



    //FUNCTION: Merge_s
    //EXPLANATION: This function receives an array from it's caller full of integers and four integers
    // that represent the beginning and end of the array elements, the midpoint and
    // the midpoint + 1. This function sorts the array by the merge sort method. And
    // returns the sorted array.
    //
    //INPUT: This function receives as input from it's caller an array of integers. It also
    // receives as input four pass by reference integer that represent the beginning
    // and end of the array elements and the midpoint and the midpoint + 1.
    //
    //OUTPUT: This function outputs to it's caller an array of integers sorted partially in
    // ascending order and all of the pass by reference integers.

    void Merge_s (int ints [], int & ltfirst, int & ltlast,
    int & rtfirst, int & rtlast)
    {
    int m; //increment variable
    int i = ltfirst; //increment variable
    static int temp [max_array_size]; //temp array ints
    int savefirst = ltfirst; //save variable

    //First while loop.
    while ((ltfirst <= ltlast) && (rtfirst <= rtlast))
    {
    if (ints [ltfirst] < ints [rtfirst])
    {
    temp = ints[ltfirst];
    ++ltfirst;
    }
    else
    {
    temp = ints[rtfirst];
    ++rtfirst;
    }
    ++i;
    }

    //Second while loop.
    while (ltfirst <= ltlast)
    {
    temp = ints[ltfirst];
    ++ltfirst;
    ++i;
    }

    //Third while loop.
    while (rtfirst <= rtlast)
    {
    temp = ints [rtfirst];
    ++rtfirst;
    ++i;
    }

    //For loop for the transfer of the temp array to the good array.
    for (m = savefirst; m <= rtlast; ++m)
    ints [m] = temp [m];
    }



    //FUNCTION: Insertsort
    //EXPLENATION: This function receives an array from it's caller full of integers of size size. This
    // function sorts the array by the insertion sort method. And returns the sorted
    // array.
    //
    //INPUT: This function receives as input from it's caller an array of integers. It also
    // receives as input one pass by reference integer that represents the number of
    // element in the array.
    //
    //OUTPUT: This function outputs to it's caller an array of integers sorted in accending
    // order.

    void Insertsort (int ints [], int & size)
    {
    int k; //increment variable
    int j; //increment variable
    int save; //integer place holder.

    for ((k = (size - 1 )); k >= 0; --k)
    {
    j = k + 1;
    save = ints [k];
    ints [size + 1] = save;
    while ( save > ints [j] )
    {
    ints[j - 1] = ints[j];
    ++j;
    }
    ints [j - 1] = save;
    }
    }



    //FUNCTION: get_int
    //EXPLANATION: This function receives an open file by a file stream. It reads off the current
    // integer that the stream is pointing to and returns it to it's caller
    //
    //INPUT: This function receives as input a filestream and an integer that is pass by
    // reference.
    //
    //OUTPUT: This function outputs to it's caller a filestream and an integer that is pass by
    // reference that contains a new integer that was off of the file.

    void get_int (ifstream & in, int & integer)
    {
    //Local Variables
    int number; //number of off file.

    //If not end of file, pull another integer off.
    if (in.peek() != EOF)
    {
    in >> number;
    integer = number;
    }
    xx }


    Testing
    Testing
    Testing
  • Systems
    Systems Posts: 14,873
    edited September 2007
    Wow... the paste and post actually takes out the indents.



    Funny thing is that I didn’t use it ever again until the game Never Winter Nights came out about 5 years ago. It used a c type language in module design. I got back into it pretty good, created a kick arss module but NWN2 came out and ended it all. I'll probably never program again. I'll stick to building servers :)
    Testing
    Testing
    Testing
  • audiobliss
    audiobliss Posts: 12,518
    edited September 2007
    Dang. I don't wanna hafta write that one!
    Jstas wrote: »
    Simple question. If you had a cool million bucks, what would you do with it?
    Wonder WTF happened to the rest of my money.
    In Use
    PS3, Yamaha CDR-HD1300, Plex, Amazon Fire TV Gen 2
    Pioneer Elite VSX-52, Parasound HCA-1000A
    Klipsch RF-82ii, RC-62ii, RS-42ii, RW-10d
    Epson 8700UB

    In Storage
    [Home Audio]
    Rotel RCD-02, Yamaha KX-W900U, Sony ST-S500ES, Denon DP-7F
    Pro-Ject Phono Box MKII, Parasound P/HP-850, ASL Wave 20 monoblocks
    Klipsch RF-35, RB-51ii

    [Car Audio]
    Pioneer Premier DEH-P860MP, Memphis 16-MCA3004, Boston Acoustic RC520
  • Systems
    Systems Posts: 14,873
    edited September 2007
    audiobliss wrote: »
    Dang. I don't wanna hafta write that one!

    You probably will, that was from the 3rd class CS163. (161, 162, 163)

    I still have all my code, you wil lbe doing a lot of it, let me know and Ill paste them up :)
    Testing
    Testing
    Testing
  • lomic
    lomic Posts: 407
    edited September 2007
    So much easier with Python ;)
    import string
    states = {'NC':'North Carolina','SC':'South Carolina','GA':'Georgia','FL':'Florida','AL':'Alabama'}
    print "Enter a two-character abbreviation for North Carolina, South Carolina, Georgia, Florida, or Alabama."
    inp = raw_input(">> ")
    try:
    print "The state you entered is %s!" % states[string.upper(inp)]
    except KeyError:
    print "Unexpected input provided. Please run program again using proper input."

    Though I suppose not as useful as C++ when you're working as a software engineer!

    edit: guess it should check for lower case and have an error condition to be fair
    Dodd Audio ELP [ Tubes ] // Harman Kardon AVR330 // Parasound HCA-1203A // Denon DVD-2900
    Polk Audio LSi9, LSiC, LSi 7 // HSU STF-2 // Signal Cable Interconnects (SG BW/A2/MP)
  • Sami
    Sami Posts: 4,634
    edited September 2007
    // state.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include "state.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif


    // The one and only application object

    CWinApp theApp;

    using namespace std;

    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {

    int nRetCode = 0;
    const char* strState[][2] = {
    {"AL", "Alabama"},
    {"NC", "North Carolina"},
    {"SC", "South Carolina"},
    {"GA", "Georgia"},
    {"FL", "Florida"},
    NULL
    };

    char abb[256];

    cout << "Enter a two-character abbreviation for North Carolina, " << endl;
    cout << "South Carolina, Georgia, Florida, or Alabama.";
    cout << "\n\n";
    cin >> abb;
    cout << "\n\n";

    int n = 0;
    while (strState[n][0] != NULL)
    {
    if (!stricmp(abb, strState[n][0]))
    {
    cout << "The state you entered is " << strState[n][1] << "!" << "\n\n";
    break;
    }
    n++;
    if (strState[n][0] == NULL)
    {
    cout << "The state you entered is not on the list.\n\n";
    break;
    }
    };
    system("pause");

    return nRetCode;
    }
  • audiobliss
    audiobliss Posts: 12,518
    edited September 2007
    Wow. I recognize about 3% of that code. You do that stuff for a living? With C++?

    Why do I get a fatal error about "state.h" when I try to run it in VisualC++ 2005?
    Jstas wrote: »
    Simple question. If you had a cool million bucks, what would you do with it?
    Wonder WTF happened to the rest of my money.
    In Use
    PS3, Yamaha CDR-HD1300, Plex, Amazon Fire TV Gen 2
    Pioneer Elite VSX-52, Parasound HCA-1000A
    Klipsch RF-82ii, RC-62ii, RS-42ii, RW-10d
    Epson 8700UB

    In Storage
    [Home Audio]
    Rotel RCD-02, Yamaha KX-W900U, Sony ST-S500ES, Denon DP-7F
    Pro-Ject Phono Box MKII, Parasound P/HP-850, ASL Wave 20 monoblocks
    Klipsch RF-35, RB-51ii

    [Car Audio]
    Pioneer Premier DEH-P860MP, Memphis 16-MCA3004, Boston Acoustic RC520
  • Sami
    Sami Posts: 4,634
    edited September 2007
    Yes, Visual C++ is my main tool at work. That's a win32 console project created by VC++, should work with express as well. state.h is just the header file, you can leave it out. Once you get into classes, objects, polymorph., inheritance, etc. then it's C++. The above is more like C with C++ syntax.

    Get it complied and debug it, it should give you couple of hints and it certainly is a much better way of handling the task than your original code. If you want me to break it down for you, I will. With software you want to avoid rewriting code, even if it is copy-and-paste and that's one of the huge advantages C++, or any object oriented language, has over procedural languages.

    Any questions you have, just let me know and I will be happy to help you. I'll help you out with your homework as long as you don't expect me to write your assingments, you won't learn anything that way.
  • audiobliss
    audiobliss Posts: 12,518
    edited September 2007
    I've tried messing with the code for a while, but I still can't get it to work. I did notice to add the #include< iostream > so it would recognize namespace, though.

    But I'm in the first C++ programming class, we're just in the fourth chapter, and I'm not going into programming, so I really have no clue what your code is. I don't even have any idea if we'll get into that stuff in this class. I'm still getting confused with the cin versus cin.get (and cin.ignore) versus getline(cin, name), as that's what we just covered.

    But just for the fun of it, I would love it if you would go through at least just the major part of your code and explain what it does.

    What's the deal with the CWinApp? VC++ is telling me it doesn't support default-int, but I've never seen that before, so I have no clue how to specify int.
    Jstas wrote: »
    Simple question. If you had a cool million bucks, what would you do with it?
    Wonder WTF happened to the rest of my money.
    In Use
    PS3, Yamaha CDR-HD1300, Plex, Amazon Fire TV Gen 2
    Pioneer Elite VSX-52, Parasound HCA-1000A
    Klipsch RF-82ii, RC-62ii, RS-42ii, RW-10d
    Epson 8700UB

    In Storage
    [Home Audio]
    Rotel RCD-02, Yamaha KX-W900U, Sony ST-S500ES, Denon DP-7F
    Pro-Ject Phono Box MKII, Parasound P/HP-850, ASL Wave 20 monoblocks
    Klipsch RF-35, RB-51ii

    [Car Audio]
    Pioneer Premier DEH-P860MP, Memphis 16-MCA3004, Boston Acoustic RC520
  • jdhdiggs
    jdhdiggs Posts: 4,305
    edited September 2007
    So are all of you nerds, geeks, or just dorks? :p
    There is no genuine justice in any scheme of feeding and coddling the loafer whose only ponderable energies are devoted wholly to reproduction. Nine-tenths of the rights he bellows for are really privileges and he does nothing to deserve them. We not only acquired a vast population of morons, we have inculcated all morons, old or young, with the doctrine that the decent and industrious people of the country are bound to support them for all time.-Menkin
  • audiobliss
    audiobliss Posts: 12,518
    edited September 2007
    I'm not sure. Probably just whichever one you are. ;)
    Jstas wrote: »
    Simple question. If you had a cool million bucks, what would you do with it?
    Wonder WTF happened to the rest of my money.
    In Use
    PS3, Yamaha CDR-HD1300, Plex, Amazon Fire TV Gen 2
    Pioneer Elite VSX-52, Parasound HCA-1000A
    Klipsch RF-82ii, RC-62ii, RS-42ii, RW-10d
    Epson 8700UB

    In Storage
    [Home Audio]
    Rotel RCD-02, Yamaha KX-W900U, Sony ST-S500ES, Denon DP-7F
    Pro-Ject Phono Box MKII, Parasound P/HP-850, ASL Wave 20 monoblocks
    Klipsch RF-35, RB-51ii

    [Car Audio]
    Pioneer Premier DEH-P860MP, Memphis 16-MCA3004, Boston Acoustic RC520
  • jdhdiggs
    jdhdiggs Posts: 4,305
    edited September 2007
    So all three, good to have that settled....
    There is no genuine justice in any scheme of feeding and coddling the loafer whose only ponderable energies are devoted wholly to reproduction. Nine-tenths of the rights he bellows for are really privileges and he does nothing to deserve them. We not only acquired a vast population of morons, we have inculcated all morons, old or young, with the doctrine that the decent and industrious people of the country are bound to support them for all time.-Menkin
  • Sami
    Sami Posts: 4,634
    edited September 2007
    I don't work with console apps myself but I believe the difference between string::getline and cin/cout is C++ and C. I'll go through my earlier code in the next post.
  • Sami
    Sami Posts: 4,634
    edited September 2007
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {

    int nRetCode = 0;

    // here you define static string matrix so when looping to see if the user entry
    // matches any of the states, you can display the state name that is grouped
    // together with the abbr.

    // const means you can't change the string runtime, it's static and not going
    // to be changed by any process, very useful when passing parameters that
    // you do not want anyone to change, kind of like
    // "you can use my speakers to listen but don't modify them"

    // [] means that the compiler will automatically allocate memory for the string
    // and you don't have to worry about string length

    // NULL at the end is the end of the list, very useful to make sure you don't
    // run into access violations

    const char* strState[][2] = {
    {"AL", "Alabama"},
    {"NC", "North Carolina"},
    {"SC", "South Carolina"},
    {"GA", "Georgia"},
    {"FL", "Florida"},
    NULL
    };

    // what's the danger of this statement? I couldn't use string with cin
    // in Visual Studio and didn't want to play around with it too long
    char abb[256];

    cout << "Enter a two-character abbreviation for North Carolina, " << endl;
    cout << "South Carolina, Georgia, Florida, or Alabama.";
    cout << "\n\n";
    cin >> abb;
    cout << "\n\n";

    int n = 0;

    // lets loop until we find the end of the state list...
    while (strState[n][0] != NULL)
    {
    // if the user input matches state in the list at n location

    // by using stricmp instead of strcmp you dont have to worry about
    // lower/upper case
    if (!stricmp(abb, strState[n][0]))
    {
    // abb matched, lets display the state name
    cout << "The state you entered is " << strState[n][1] << "!" << "\n\n";
    // we found it, no need to loop anymore, lets break the loop
    break;
    }
    // no match yet, lets go to the next state in list
    n++;
    // if we are at the end of the list, display that no match was found
    if (strState[n][0] == NULL)
    {
    cout << "The state you entered is not on the list.\n\n";
    break;
    }
    };
    system("pause");

    return nRetCode;
    }
  • Sami
    Sami Posts: 4,634
    edited September 2007
    If you want it to compile, you need to create a WIN32 console app in Visual Studio. If you're using just a regular app, copy the code inside _tmain to your main function.

    Don't forget to put the arguments into your main function even if you don't use them inside your code.