ned help, new to developing

Discussion in 'iOS Development' started by flyingguitar, Jul 20, 2009.

  1. flyingguitar

    flyingguitar Active Member

    Joined:
    May 14, 2008
    Messages:
    1,860
    Likes Received:
    11
    Device:
    iPhone 6
    I wrote my first code, and got an error when I tried to compile it.

    this is the code

    Code:
    // my first program in C++
    
    #include <iostream>
    using namespace std;
    
    int main ()
    {
        cout << "My name is John."; 
        return 0;
    }
    
    when I try to compile it I get this error message

    Code:
      [Linker error] undefined reference to `__cpu_features_init' 
      ld returned 1 exit status 
    I'm using this compiler on windows XP

    any help?
  2. wibble

    wibble New Member

    Joined:
    Mar 16, 2008
    Messages:
    176
    Likes Received:
    0
    You're missing libs.

    Don't use MinGW
  3. flyingguitar

    flyingguitar Active Member

    Joined:
    May 14, 2008
    Messages:
    1,860
    Likes Received:
    11
    Device:
    iPhone 6
  4. ZhiZhi778

    ZhiZhi778 Member

    Joined:
    Jan 20, 2008
    Messages:
    936
    Likes Received:
    2
    Device:
    iPhone 3G (Black)
    ;D another way to do the "Hello World" app (almost) every dev starts with x)

    cygwin is a good way to go also for the future

    Please Register or Log in to view images

  5. flyingguitar

    flyingguitar Active Member

    Joined:
    May 14, 2008
    Messages:
    1,860
    Likes Received:
    11
    Device:
    iPhone 6
    ok, I've been playing with this all day.

    I want to know if you can use the 'if' and 'else' statements with text strings.

    for example

    Code:
    // if and else
    
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
        string color = color, orange = orange;
        
        cout << "Enter your favorite color: ";
        getline (cin, color);
        if (color == orange) 
        cout << "\nThat is the coolest color ever!!!";
              else 
              cout << "\nnot as cool as orange.";
        return 0;
    } 
    I hope you see what I am trying to do here, basically the same as this.

    Code:
    // if and else
    
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int a = 0, b = 17;
        
        cout << "I am thinking of a number between 1 and 100, what is it: ";
        cin >> a;
        if (a == b) 
        cout << "\nThat was the number I was thinking of!";
              else 
              cout << "\nthat is not it.";
        return 0;
    } 
    is this possible?? or am I just doing it wrong?
  6. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    It's possible, but that code is not going to work:

    First, this line is doing nothing:
    Code:
    string color = color, orange = orange;
    In that line, you are saying that the variable color is going to be the variable color, same with the variable orange.

    If you want to initialize the string with text, it has to be:
    Code:
    string orange = "orange";
    Also, I'm not sure you can do:
    Code:
    color == orange
    Maybe you can, since they are both variables, but to compare strings, you usually have to use a function, I think it's something like strcmp or something like that.
  7. wibble

    wibble New Member

    Joined:
    Mar 16, 2008
    Messages:
    176
    Likes Received:
    0
    use the compare function in the std string class
  8. flyingguitar

    flyingguitar Active Member

    Joined:
    May 14, 2008
    Messages:
    1,860
    Likes Received:
    11
    Device:
    iPhone 6
    ok, last question

    what is wrong with this code

    Code:
    // data structures and arrays
    
    #include <iostream>
    #include <string>
    #include <sstream>
    
    using namespace std;
    
    int number;
    struct movies {
           string title;
           int year;
           } users [80];
    
    void printmovies (movies movie);
    
    int main ()
    {
        int n;
        string mystry;
        
        cout << "How many movies do you like?: ";
        cin >> number;
        if (number>80){
           cout << "Error: not enough memory";
           goto end;
           }
        for (n=0; n<number; n++){
            cout << "Enter title: ";
            getline (cin, users[n].title);
            cout << "Enter year: ";
            getline (cin, mystry);
            stringstream (mystry) >> users[n].year;
            }
        cout << "\nYou have entered\n";
        for (n=0; n<number; n++){
            printmovies (users [n]);
            }
        end:       
        return 0;
    }
    
    void printmovies (movies movie){
         cout << "\n" << movie.title;
         cout << " (" << movie.year << ")";
         }
    
    it compiles without any errors but when I run it I get this

    Please Register or Log in to view images



    even though I clearly stated
    Code:
    getline (cin, users[n].title)
    right after
    Code:
    cout << "Enter title: ";
    did I do anything wrong?

Share This Page