HELP ME!!!!!! c++

Discussion in 'Computing, Science, and Technology' started by Gatzy118, Aug 11, 2008.

  1. Gatzy118

    Gatzy118 New Member

    Joined:
    Jan 7, 2008
    Messages:
    350
    Likes Received:
    0
    Device:
    iPod touch
    Hi, ive written this in c++ and i didn't know if i am using the arguments correctly? If i am then why am i getting an error that says this when i compile: Lvalue required in function main(int,char * *)

    this is the code i have got:

    Code:
    #include <iostream>
    using namespace std;
    
    void cyd()
    {
    cout << "chose cydia all";
    }
    
    
    void inst()
    {
    cout << "chose installer all";
    }
    
    
    void instcyd()
    {
    cout << "chose installer and cydia all";
    }
    
    
    void cydcust()
    {
    cout << "chose cydia only";
    }
    
    void instcust()
    {
    cout << "chose installer only";
    }
    
    
    void instcydcust()
    {
    cout << "chose installer and cydia only";
    }
    
    
    int main(int argc, char *argv[])
    {
    
    
    
    if (argc != 2 || 3 || 4)
    {
    cout << "Usage: " << argv[0] << " [c or i for packages], [o for only custom]";
    }
    
    if (argc == 2 && argv[1] == "i")
    	inst();
    
    else if (argc == 2 && argv[1] = "c")
    	cyd();
    
    else if (argc == 3 && argv[1] == "i" && argv[2] == "c")
    	instcyd();
    
    
    else if (argc == 3 && argv[1] == "i" && argv[2] == "o")
    	instcust();
    
    else if (argc == 3 && argv[1] == "c" && argv[2] == "o")
    	cydcust();
    
    else if (argc == 4 && argv[1] == "i" && argv[2] == "c" && argv[3] == "o")
    	instcydcust();
    else
    cout << "error has occured";
    
    
    
    return 0;
    }
    
    thanks everyone, i know this is the wrong forum but i think someone may still be able t help.
  2. jonmisurda

    jonmisurda New Member

    Joined:
    Jul 19, 2008
    Messages:
    46
    Likes Received:
    0
    Device:
    iPad 2 (Black)
    annoyingly you have to repeat what you're comparing to when doing ORs:

    Code:
    if (argc != 2 || 3 || 4)
    should be:

    Code:
    if(argc != 2 || argc != 3 || argc != 4 )
    Second, you cannot compare strings using ==, you need to use the function strcmp() which returns 0 if two strings are equal. Add the header:

    [code#include <cstring>[/code]

    and change all your comparisons of argv[] elements to:

    Code:
    strcmp(argv[1] , "i") == 0
    For instance:

    Code:
    if (argc == 2 && strcmp(argv[1] ,"i") ==0 )
    	inst();
    The lvalue error means that you tried to assign to something (anything you can assign to is called an l-value [L is for left hand side]) that you shouldn't have. In one of your ifs you did:

    Code:
    argv[1] = "c"
    You meant to do == comparison but instead did = assignment, however as this is a string, you don't want to do either and use strcmp here as I showed before.
  3. *Soul~Of~iTouch*

    *Soul~Of~iTouch* New Member

    Joined:
    Apr 21, 2008
    Messages:
    542
    Likes Received:
    0
    Device:
    iPod touch
    Tell me one thing: Why does this look so much like Java?!
  4. jonmisurda

    jonmisurda New Member

    Joined:
    Jul 19, 2008
    Messages:
    46
    Likes Received:
    0
    Device:
    iPad 2 (Black)
    Because C++ was created in 1979/1980 and Java was created in the early 1990s. Both are Object Oriented languages based on the syntax of C (created around 1976). Objective-C looks very similar to them as well. Other languages based on C's syntax include JavaScript, perl, and many others...

    Java's syntax was meant to simplify some of the things that are complicated in C++.

    I replied in your other thread that I'd help you with some questions you had. Just shoot me a PM.

Share This Page