Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,163 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,910 people online right now. Registration is fast and FREE... Join Now!




help me please

 
Reply to this topicStart new topic

help me please, expected primary-expression before ',' token

Goten_2309
7 Dec, 2007 - 09:13 AM
Post #1

New D.I.C Head
*

Joined: 7 Dec, 2007
Posts: 1


My Contributions
CODE
#include <iostream>
#include <string>
using namespace std;
void fst(string ans[3]);
int main()
{
    int choice,quiz;
    string ques[3];
    string ans[3];
    cin>>choice;

    if(choice==1)
    {
         ques[0]="name a thing:";
         ques[1]="now name an unusal food:";
         ques[2]="now give me a verb:";
         for(quiz=0;quiz<3;quiz++)
         {
                cout<<ques[quiz];
                cin>>ans[quiz];
            
         }
        fst(string, ans[3]);//this is the error line
        
    }
    system("pause");
    return 0;
}

void fst(string ans[3])
{
     cout<<ans[0]<<endl;
}


i get this error code:expected primary-expression before ',' token

This post has been edited by Goten_2309: 7 Dec, 2007 - 09:30 AM
User is offlineProfile CardPM
+Quote Post

Jingle
RE: Help Me Please
7 Dec, 2007 - 09:16 AM
Post #2

D.I.C Head
**

Joined: 20 Oct, 2007
Posts: 249


My Contributions
I don't have time to tell you how to fix your code at the moment, but when posting code you should put a / in the last [/code] box.

This post has been edited by Jingle: 7 Dec, 2007 - 09:18 AM
User is offlineProfile CardPM
+Quote Post

Sothrie
RE: Help Me Please
7 Dec, 2007 - 09:48 AM
Post #3

New D.I.C Head
*

Joined: 3 Dec, 2007
Posts: 24


My Contributions
As I recall, in C++ you declare a variable explicitly as a type. Take as an example your function:
CODE
void fst(string ans[3])

There's only one variable, an array of type string. Try calling it with only the array variable. Replace your erroring line with something like thus:
CODE
fst(ans[3]);

User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Help Me Please
7 Dec, 2007 - 10:41 AM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,446



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Yes, the comma after "string" will surely make that into two arguments.
User is online!Profile CardPM
+Quote Post

Bench
RE: Help Me Please
7 Dec, 2007 - 10:51 AM
Post #5

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 617



Thanked: 14 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
The input parameter for your fst function needs to be an array of string's, not just one individual string, which is what you get from the subscript next to the array name. (and since the array is indexed 0-2, then you're actually accessing something which is out-of-bounds anyway)

You probably want to make this line
fst(string, ans[3]);//this is the error line
look like this
fst( ans );

This post has been edited by Bench: 7 Dec, 2007 - 10:53 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 11:58PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month