problem with switch command

This is a discussion on problem with switch command within the C++ Programming forums, part of the General Programming Boards category; Please see attached file. I am getting 5 errors of "function does not take 3 parameters", one error at each ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    27

    Question problem with switch command

    Please see attached file.

    I am getting 5 errors of "function does not take 3 parameters", one error at each case.

    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    just look at your code....

    Code:
    void print (string names[50], int count, int areacode[50], int numbers[50]);
    Code:
    print (areacode, numbers, names);
    you define the function print to take four varibales in it's prototype and only pass in three when you call it...

    i assume you wanted something a bit more like this:

    Code:
    print (names, count, areacode, numbers);
    yet i have no clue why you define print to arrays when you oly pass in single integers........

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    27

    more help needed please

    I've taken care of the previous errors, but now I'm getting this:

    "conditional expression of type 'class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >' is illegal"

    I have no idea what this means...

    PLEASE HELP!!
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    That program still had two errors in it. First of all you can't use cin to get more then one character unless you use a speciaal function. The following statement:

    Code:
    cout<<"Enter name to be deleted: ";
    cin>>del;
    should be replaced by:

    Code:
    cout<<"Enter name to be deleted: ";
    getline(cin, del);
    the getline function will take all the symbols entered into the cin stream and save them into del untill it finds a newline character ('\n').

    Second of all you made quite an elemantairy mistake in the if statement that gave you the error:

    Code:
    if (names[item]=del)
    basically what you check here is if the del string got succesfully copied into names[item]. you would get better results when using:

    Code:
    if (names[item] == del)
    but don;t worry about the second one to much evryone does it so now and then .

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    27

    dirX

    Thanks,
    I had just figured out the first one before I checked your reply.
    I fixed the second one--DUH!

    but now I'm getting 2 more errors...

    I think it may be a linking problem with my external file???


    Here's my "phonelist.txt" and it's located in the same directory as my program:

    419 4731212 Anna
    313 8561212 Bobby
    517 7341212 Cindy
    800 5551212 Zoe
    Attached Files Attached Files
    Last edited by DoItAllMom115; 04-16-2003 at 08:19 PM.

  6. #6
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    The linking error you got was because the prototype of the save function was different from it's initialization. You have to replace the initialization with:

    Code:
    void save(int areacode[50], int numbers[50], string names[50], int count)
    {
    	ofstream outfile;
    	outfile.open("phonelist.txt");
    	outfile<<areacode[50]<<numbers[50]<<names[50];
    	outfile.close();
    }
    you forgot the int count. Further more you have to make sure that you initialize all the variables you use. else you get pretty strange results.

    Also you might wish to alter your print a bit so it will only output entries that actually exist and not just go through all the elements in the list. you could do this by limiting it's for loop till to aslong as item is less then count. Also i have my doubts about your save function you may wish to look over that. THere is most probably some other stuff in there i did not see yet. I only skimmed it over a bit.

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    27

    I'm still trying

    I've got the program to compile.
    The print function works ok, but none of the others do.

    Mostly they just loop through the choices a few times.

    HELP!!
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Problem with switch loop
    By sweetorangepie in forum C Programming
    Replies: 3
    Last Post: 03-20-2008, 10:26 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 03:49 PM

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