Thread: Why won't this work

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    6

    Angry Why won't this work

    Hi I need help finding out what I am doing wrong.
    I keep getting errors telling me that "v cannot be used as a function" "Parse error before the first"{"" and "implicit declaration of function `int system(...)' "
    What is wrong??

    Code:
    #include <stdio.h>
    #include <iostream.h>
    
    char ve;
    char v(ve)
    {
         cout<< "Please input a Verb: ", cin>>ve;
         return (ve);
    }
    
    int main(int argc, char *argv[])
    {
      char verb1, verb2, verb3, verb4;
      v(verb1);
      v(verb2);
      v(verb3);
      v(verb4);
      cout<< "Here are the verbs you typed: ", verb1, verb2, verb3, verb4;
      system("Pause");
      return 0;
    }
    thanx

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    char ve;
    char v(ve)
    {
    Your K&R style function is backward. It should be like this:
    Code:
    char v(ve)
    char ve;
    {
    But since C++ doesn't allow such things you would be better off doing this:
    Code:
    char v(char ve)
    {
    Of course, that doesn't do too much anyway because ve is a local variable and you seem to be expecting the data input to persist back in main. This is only the case if you pass ve as a reference or a pointer. In this case a pointer would be better because your names suggest strings instead of individual characters.

    >"implicit declaration of function `int system(...)' "
    System lives in cstdlib. You neglected to include that header. All fixed, your program would look more like this (with my own embellishments added):
    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    char *v(char *ve)
    {
      cout<< "Please input a Verb: ";
      cin.getline(ve, 100); // We magically know that ve is 100 chars long
      return (ve);
    }
    
    int main()
    {
      char verb1[100], verb2[100], verb3[100], verb4[100];
      cout<< v(verb1) <<endl;
      cout<< v(verb2) <<endl;
      cout<< v(verb3) <<endl;
      cout<< v(verb4) <<endl;
      return 0;
    }
    My best code is written with the delete key.

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164

    Re: Why won't this work

    Originally posted by gooey kablooey
    Hi I need help finding out what I am doing wrong.
    I keep getting errors telling me that "v cannot be used as a function" "Parse error before the first"{""
    What prelude said.

    Originally posted by gooey kablooey
    and "implicit declaration of function `int system(...)' "
    What is wrong??
    Using system("pause");
    Why not use C++?
    Code:
     cin.get();
    will do what you want.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    what is
    Code:
    sytem( "pause");

    sorry but i didnt hear about it before

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >sorry but i didnt hear about it before
    On platforms that support a "pause" command, system calls that command. For example, on Windows this will give a little message that let's the program wait for user interaction:
    Code:
    Press any key to continue...
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM