Thread: modigy array elements..?

  1. #16
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Store the current value in a second variable?

  2. #17
    Registered User snapshooter's Avatar
    Join Date
    Sep 2004
    Posts
    37
    sorry this is correct:

    Code:
    #include <iostream>
    #include <stdlib.h>
    
    using namespace std;
    
    void messageFunction();
    void Header();
    
    int main()
    {
    
    
    int a=0;
    
    int num;
    
    Titlos();
    cout<<endl;
    messageFunction();
    
    cout<<"Choose an option:"<<endl;
    cin>>num;
    
    while (num==1&&a<5)
    {
          a++;
    
          cout<<"You bought seat "<<a<<endl;
          cin>>a;
          break;
               
    }
    
    return main();
    
      system("PAUSE");	
      return 0;
    }
    
    void messageFunction(void)
    {
        cout<<"Type 1 for First class"<<endl;
    } 
    
    void Header()
    
    {
        cout<<"********Exercise 3 Solution********"<<endl;
    }
    could someone solve my prob?
    Ready..Steady..Doom!!!

  3. #18
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >return main();
    Recursive calls to main aren't legal C++. Use a loop instead.
    My best code is written with the delete key.

  4. #19
    Registered User snapshooter's Avatar
    Join Date
    Sep 2004
    Posts
    37
    ok, i have tryied a lot of patterns but with no result..
    Ready..Steady..Doom!!!

  5. #20
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >i have tryied a lot of patterns but with no result..
    It would help if you explained exactly what input you want to give, and what output you expect. There are many times when just looking at the code doesn't help us to understand your intentions at all. Is this what you want?
    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    void messageFunction();
    void Header();
    
    int main()
    {
      int a=0;
      int num;
    
      Header();
    
      do
      {
        cout<<endl;
        messageFunction();
    
        cout<<"Choose an option:"<<endl;
        cin>>num;
    
        if (num == 1)
        {
          a++;
          cout<<"You bought seat "<< a <<endl;
        }
        else
        {
          break;
        }
      } while (a < 5);
    
      system("PAUSE");
    
      return 0;
    }
    
    void messageFunction(void)
    {
      cout<<"Type 1 for First class"<<endl;
    } 
    
    void Header()
    {
      cout<<"********Exercise 3 Solution********"<<endl;
    }
    If not, you'll need to describe what you want, in painful detail.
    My best code is written with the delete key.

  6. #21
    Registered User snapshooter's Avatar
    Join Date
    Sep 2004
    Posts
    37
    Yes..thanks!
    Ready..Steady..Doom!!!

  7. #22
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Quote Originally Posted by Prelude
    >I meant as 1 (which would be array[0]).
    Your code was misworded too then:
    Code:
    int array[0]; // Illegal
    int array[1]; // Legal, but kind of silly because only array[0] is available
    No my code worked as intended in my compiler o-o

    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int in;
        int array[0];
        array[0]=0;
        cout<<"Please enter a number";
        cin>>in;
        array[0]=in;
        cout<<"Array value is now:"<<array[0];
        system("PAUSE");
        return 0;
    }
    To code is divine

  8. #23
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    No my code worked as intended in my compiler o-o
    Which means your compiler is not conforming to the standard and will be exhibiting undefined behavior. Don't even get Prelude started on that.

  9. #24
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >No my code worked as intended in my compiler o-o
    My compiler can beat up your compiler.
    My best code is written with the delete key.

  10. #25
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    My compiler can beat up your compiler.
    Told you so...

  11. #26
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Quote Originally Posted by Prelude
    My compiler can beat up your compiler.
    Dev-CPP + $120 > Visual C++


    edit: not really, but I do like my money in my pocket for now
    To code is divine

  12. #27
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Dev-CPP + $120 > Visual C++
    Who said I was talking about Visual C++? I was making a "My dad can beat up your dad" joke, but that doesn't change the fact that your excuse for broken code was that it happened to work on your implementation. That's a horrible excuse, but I'll let it slide because Dev-C++ really does compile it without warnings. Though I'll continue to wonder how you thought an array of size 0 should work.
    My best code is written with the delete key.

  13. #28
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Though I'll continue to wonder how you thought an array of size 0 should work.
    Or why you'd want it to...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding More Array Elements?
    By Vermillion in forum C++ Programming
    Replies: 2
    Last Post: 09-14-2008, 10:02 PM
  2. coping elements not in array
    By lord in forum C++ Programming
    Replies: 2
    Last Post: 08-04-2008, 07:53 PM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. A simple question about selecting elements in an array
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 10:37 PM