varuables

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
    Posts
    56

    varuables

    i am a very new to c++
    but what's wrong about this
    ?
    Code:
    #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:");
    
      cin.get(user));
    
      printf ("enterpassword")
    
      cin.get(password))
    }
    if (name, stefan))
    {
    if (password, 112112))
    {
    printf ("your correct");
    }
    printf ("correct");
    return  0;
    }
    [message]
    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 `.'
    [/message]
    i try to read the message but i don't get it please help!!
    thanks
    Last edited by gamer; 02-09-2003 at 04:46 AM.
    if x == y , y == x

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    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
    Posts
    291

    Re: varuables

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

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

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    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.

    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
    	double value=34;
    
    	cout.fill('*');
    	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