This is a discussion on varuables within the C++ Programming forums, part of the General Programming Boards category; i am a very new to c++ but what's wrong about this ? Code: #include <stdio.h> int main(int argc, char ...

  1. #1
    Registered User
    Join Date
    Jan 2003


    i am a very new to c++
    but what's wrong about this
    #include <stdio.h>
    int main(int argc, char *argv[])
      char cin[20]
      char user[200];
      char password[200];
      printf ("hello world\n");
      printf ("enter user name:");
      printf ("enterpassword")
    if (name, stefan))
    if (password, 112112))
    printf ("your correct");
    printf ("correct");
    return  0;
    c:\windows\desktop\stefan-c++\v\untitled1.cpp: In function `int main(int, char **)':
    c:\windows\desktop\stefan-c++\v\untitled1.cpp:8: parse error before string constant
    c:\windows\desktop\stefan-c++\v\untitled1.cpp:12: `cin' undeclared (first use this function)
    c:\windows\desktop\stefan-c++\v\untitled1.cpp:12: (Each undeclared identifier is reported only once
    c:\windows\desktop\stefan-c++\v\untitled1.cpp:12: for each function it appears in.)
    c:\windows\desktop\stefan-c++\v\untitled1.cpp:12: parse error before `)'
    c:\windows\desktop\stefan-c++\v\untitled1.cpp: At top level:
    c:\windows\desktop\stefan-c++\v\untitled1.cpp:24: syntax error before string constant
    c:\windows\desktop\stefan-c++\v\untitled1.cpp:27: syntax error before `.'
    i try to read the message but i don't get it please help!!
    Last edited by gamer; 02-09-2003 at 05:46 AM.
    if x == y , y == x

  2. #2
    Join Date
    Aug 2001
    Groningen (NL)
    You should read your code more carefully. The way you use printf() is wrong. It should be printf ("text");. Also, code should be within a function. So what you have written after your main-function cannot be there. Or just replace your } to the end of the program, i.e. after the return 0. And also, the cin.get(); after the return 0 is unreachable code.

  3. #3
    Registered User
    Join Date
    Oct 2002

    Re: varuables

    Look over your code again, your missing semicolon's at the end of multiple lines.

      cin.get(user)); // why is there three paranthesis here ?
    You should probably change your get statment to :
      cin.get(user, 200, '\n');
    Your if statments are also very messed up.

  4. #4
    Registered User
    Join Date
    Jan 2003
    Since you're coding C++, use cout instead of printf. True printf has the cool feature of parsing all the "%s" and "%d". But all this can be done in cout, just a bit harder. Using cout is the real C++ way.

    Note: You can't mix <iostream> with <iostream.h> if you include the std namespace.

    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    	double value=34;
    	cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);
    	cout << "HEY!" << setw(10) << value << endl;
    	return 0;
    Prints out:
    HEY! *****34.00

Popular pages Recent additions subscribe to a feed

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