• Lucid Dreaming - Dream Views




    Page 3 of 7 FirstFirst 1 2 3 4 5 ... LastLast
    Results 51 to 75 of 165
    1. #51
      Gentlemen. Ladies. slayer's Avatar
      Join Date
      Mar 2007
      Gender
      Location
      Right here... Reputation: 9999
      Posts
      4,902
      Likes
      473
      DJ Entries
      4
      Code:
      #include <iostream>
      using namespace std;
      
      int main()
      {
          int a;
          a = 0;
      
          if ( a < 10 )
          {
              do
              {
                  cout << a << " Adding one." << endl;
                  a++;
      
                  if ( a == 10 )
                  {
                      cout << a << " is the right number!" << endl;
                      return 0;
                  }
      
              } while ( a < 10 );
          }
      }
      Got my loop set up so that if a doesn't equal 10, then it keeps adding to it until it does. Pretty neat stuff right there :3

    2. #52
      Ex Tech Admin Achievements:
      Created Dream Journal Tagger First Class Veteran First Class 10000 Hall Points Populated Wall Referrer Gold Made lots of Friends on DV
      slash112's Avatar
      Join Date
      Nov 2008
      Gender
      Location
      Sunny Scotland
      Posts
      5,113
      Likes
      1567
      DJ Entries
      29
      Fixed my problem, thanks to A Roxxor

      Now time to learn that bastard of a language

      Also, nice one slayer.

    3. #53
      Member L815's Avatar
      Join Date
      Mar 2008
      Gender
      Posts
      78
      Likes
      0
      Here's another version of what slayer posted:
      Code:
      #include <iostream>
      
      using std::cout;
      using std::endl;
      
      int main (void) {
      
          int a = 0;
      
          while (a < 10) {
              a++;
          }
          cout << "Congrats, the variable <a> hit 10!" << endl;
      
          return 0;
      }
      Just to add some more to study :p
      http://i30.tinypic.com/j79u05.jpg

    4. #54
      .. / .- –– / .- .-. guitarboy's Avatar
      Join Date
      Sep 2008
      LD Count
      Over 9000
      Gender
      Location
      Homeward Bound
      Posts
      1,571
      Likes
      49
      What's the difference between C++ and dev C++

    5. #55
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by slash112 View Post
      Cool, I have downloaded and installed code::blocks. Then it asked me what compiler to use, so I used windows visual C++ since it was already on my computer from last time I tried all this stuff.

      My problem now is that it won't build or something, I click build, then I click run, and it says I need to build it. I then tried "build and run" and it just kinda does nothing. Don't know what the fuck is wrong here.
      Tell it to use GCC instead, MinGW should be automatically installed with Code::Blocks, and it more standard.

    6. #56
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by guitarboy View Post
      What's the difference between C++ and dev C++
      Dev-C++ is a deprecated IDE, it's not a language or even a compiler. It uses the GCC compiler. The project was discontinued and merged with Code::Blocks.

      Quote Originally Posted by slayer View Post
      Code:
      #include <iostream>
      using namespace std;
      
      int main()
      {
          int a;
          a = 0;
      
          if ( a < 10 )
          {
              do
              {
                  cout << a << " Adding one." << endl;
                  a++;
      
                  if ( a == 10 )
                  {
                      cout << a << " is the right number!" << endl;
                      return 0;
                  }
      
              } while ( a < 10 );
          }
      }
      Got my loop set up so that if a doesn't equal 10, then it keeps adding to it until it does. Pretty neat stuff right there :3
      Cool But you don't need that first if statement. You just assigned a to 0, there is no reason to check if it's less than ten since you know it will be

    7. #57
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      Quote Originally Posted by ninja9578 View Post
      Cool But you don't need that first if statement. You just assigned a to 0, there is no reason to check if it's less than ten since you know it will be
      But it doesn't really matter if you do, though. It's only one extra comparison. The place you really want to use a do...while is where you need to run the data through at least one literation before you're even ready to test the condition (can't think of such a scenario of the top of my head, though).

      Also, instead of writing
      Code:
      int a;
      a = 0;
      Why not just write
      Code:
      int a = 0;
      Uses less space and is actually a bit faster.
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    8. #58
      .. / .- –– / .- .-. guitarboy's Avatar
      Join Date
      Sep 2008
      LD Count
      Over 9000
      Gender
      Location
      Homeward Bound
      Posts
      1,571
      Likes
      49
      Code:
      #include <isostream>
      
      using namespace std;
      
      int main()
      {
           int a, b, total;
      
           cout << "Enter two numbers here...;" << endl;
      
           cin >> a >> b;
      
           total= a + b;
      
           cout << "Sum equals;" <<Total << endl;
      
           system(PAUSE) ;
      
           return 0;
      }
      returns 7 errors fix it dreamviews!

    9. #59
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by guitarboy View Post
      returns 7 errors fix it dreamviews!
      Code:
      /*#include <isostream>
      
      using namespace std;*/
      
      int main()
      {
      /*     int a, b, total;
      
           cout << "Enter two numbers here...;" << endl;
      
           cin >> a >> b;
      
           total= a + b;
      
           cout << "Sum equals;" <<Total << endl;
      
           system(PAUSE) ;
      */
           return 0;
      }
      (\_ _/)
      (='.'=)
      (")_(")

    10. #60
      Ex Tech Admin Achievements:
      Created Dream Journal Tagger First Class Veteran First Class 10000 Hall Points Populated Wall Referrer Gold Made lots of Friends on DV
      slash112's Avatar
      Join Date
      Nov 2008
      Gender
      Location
      Sunny Scotland
      Posts
      5,113
      Likes
      1567
      DJ Entries
      29
      Emmmm... doesn't that basically the actual code with :

      Code:
      int main()
      {
           return 0;
      }
      ?

      I'm guessing that is some sarcastic way of saying his program can't be fixed?

    11. #61
      Ex Tech Admin Achievements:
      Created Dream Journal Tagger First Class Veteran First Class 10000 Hall Points Populated Wall Referrer Gold Made lots of Friends on DV
      slash112's Avatar
      Join Date
      Nov 2008
      Gender
      Location
      Sunny Scotland
      Posts
      5,113
      Likes
      1567
      DJ Entries
      29
      Ok, I fixed it. Suck it, Ynot .

      Code:
      #include <iostream>
      using namespace std;
      
      int main()
      {
           int a, b, Total;
      
           cout << "Enter two numbers here...;"
      
           ;cin >> a >> b;
      
           Total= a + b;
      
           cout << "Sum equals;" <<Total << endl;
      
           return 0;
      }

      I had no idea what I was doing, but it somehow worked

    12. #62
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Yeah, C++ is case sensitive.

    13. #63
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      Quote Originally Posted by guitarboy View Post
      Code:
      #include <isostream>
      It's supposed to be <iostream>, not <isostream> (input/output stream)

      Edit: The compiler will also output which lines and expressions were making the trouble. Compiling that you'd first get an error stating that <isostream> couldn't be included in the project, and the subsequent errors came because std::cout and std::cin wasn't defined (the <iostream> header defines these values so you can use them)
      Last edited by khh; 01-10-2010 at 09:01 PM.
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    14. #64
      Ex Tech Admin Achievements:
      Created Dream Journal Tagger First Class Veteran First Class 10000 Hall Points Populated Wall Referrer Gold Made lots of Friends on DV
      slash112's Avatar
      Join Date
      Nov 2008
      Gender
      Location
      Sunny Scotland
      Posts
      5,113
      Likes
      1567
      DJ Entries
      29
      I don't understand what it wrong with this. It says "error: expected primary-expression before "else"" and also "error: expected ';' before else"

      It is supposed to be that it calculates the radius or circumfrence of a circle if you input the circumfrence/radius.

      Have I done something wrong with the if/else thing?

      Code:
      #include <iostream>
      using namespace std;
      
      #define PI 3
      
      int main()
      {
      
      double r, d, circle, entered_number;
      
      cout<<"Enter 1 to find circumference, or enter 2 to find radius/diameter"<<endl;
      
      if (entered_number == 1)
      cout<<"To find circumfrence of circle, please input radius"<<endl;
      cin>>r;
      circle = PI * r * 2;
      cout<<"The circumfrence of the circle is "<<circle<<endl;
      
      else if (entered_number == 2)
      cout<<"To find radius of circle, please input circumfrence"<<endl;
      cin>>circle;
      r = circle/(PI*2);
      d = r * 2;
      cout<<"The radius of the circle is "<<r<<" and diameter is "<<d<<endl;
      
          return 0;
      }
      EDIT: Fixed it, but there is something wrong somewhere in it, even though it runs... I'll need to find that.

      EDIT2: found that problem too... a very obvious one

    15. #65
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      you've forgotten to group the code propperly. What you wrote is basically

      Code:
      #include <iostream>
      using namespace std;
      
      #define PI 3
      
      int main()
      {
      double r, d, circle, entered_number;
      
      cout<<"Enter 1 to find circumference, or enter 2 to find radius/diameter"<<endl;
      
      if (entered_number == 1) {
      cout<<"To find circumfrence of circle, please input radius"<<endl;
      }
      cin>>r;
      circle = PI * r * 2;
      cout<<"The circumfrence of the circle is "<<circle<<endl;
      else if (entered_number == 2) {
      cout<<"To find radius of circle, please input circumfrence"<<endl;
      }
      cin>>circle;
      r = circle/(PI*2);
      d = r * 2;
      cout<<"The radius of the circle is "<<r<<" and diameter is "<<d<<endl;
          return 0;
      }
      When you wanted

      Code:
      #include <iostream>
      using namespace std;
      
      #define PI 3
      
      int main()
      {
      
      double r, d, circle, entered_number;
      
      cout<<"Enter 1 to find circumference, or enter 2 to find radius/diameter"<<endl;
      
      if (entered_number == 1) {
      cout<<"To find circumfrence of circle, please input radius"<<endl;
      cin>>r;
      circle = PI * r * 2;
      cout<<"The circumfrence of the circle is "<<circle<<endl;
      
      } else if (entered_number == 2) {
      cout<<"To find radius of circle, please input circumfrence"<<endl;
      cin>>circle;
      r = circle/(PI*2);
      d = r * 2;
      cout<<"The radius of the circle is "<<r<<" and diameter is "<<d<<endl;
      }
          return 0;
      }
      If you want more than one block of code after an if/else/for/while/whatever statement, you need to enclose it in brackets. Also, it's common to indent blocks so that the end result looks like this (but it's strictly optional, C/C++ ignores excess white space)
      Code:
      #include <iostream>
      using namespace std;
      
      #define PI 3
      
      int main()
      {
      	double r, d, circle, entered_number;
      
      	cout<<"Enter 1 to find circumference, or enter 2 to find radius/diameter"<<endl;
      
      	if (entered_number == 1) {
      		cout<<"To find circumfrence of circle, please input radius"<<endl;
      		cin>>r;
      		circle = PI * r * 2;
      		cout<<"The circumfrence of the circle is "<<circle<<endl;
      	} else if (entered_number == 2) {
      		cout<<"To find radius of circle, please input circumfrence"<<endl;
      		cin>>circle;
      		r = circle/(PI*2);
      		d = r * 2;
      		cout<<"The radius of the circle is "<<r<<" and diameter is "<<d<<endl;
      	}
      	return 0;
      }
      Makes the code much cleaner, as you can see.
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    16. #66
      Ex Tech Admin Achievements:
      Created Dream Journal Tagger First Class Veteran First Class 10000 Hall Points Populated Wall Referrer Gold Made lots of Friends on DV
      slash112's Avatar
      Join Date
      Nov 2008
      Gender
      Location
      Sunny Scotland
      Posts
      5,113
      Likes
      1567
      DJ Entries
      29
      Yea, I had it all fixed up like that. And yea, all my indents went away while editing it so much, deleting, adding in stuff, I ended up deleting all the indents.

      I could make the program much better than that, but right now, I'm just using it as a learning thing. Next thing to try is to use the loop thingy (do while?), so that the program stays open and you can calculate more.

    17. #67
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      You should also loop into while loops and for loops.

      Code:
      int a = 50;
      do{
         std::cout << "I'm inside the loop " << a++ << std::endl;
      } while (a < 10);
      Code:
      int a = 50;
      while (a < 10){
         std::cout << "I'm inside the loop " << a++ << std::endl;
      }
      Have one but very important difference, see if you can figure out what it is

    18. #68
      Ex Tech Admin Achievements:
      Created Dream Journal Tagger First Class Veteran First Class 10000 Hall Points Populated Wall Referrer Gold Made lots of Friends on DV
      slash112's Avatar
      Join Date
      Nov 2008
      Gender
      Location
      Sunny Scotland
      Posts
      5,113
      Likes
      1567
      DJ Entries
      29
      Well, one of them is a while loop, and one is a do while loop. I don't really understand the difference, even after reading about it.

      I should look at this page on loops for ages. I have trouble taking in/reading that much information at once, mainly because of a short attention span. I'll just have to try...

    19. #69
      .. / .- –– / .- .-. guitarboy's Avatar
      Join Date
      Sep 2008
      LD Count
      Over 9000
      Gender
      Location
      Homeward Bound
      Posts
      1,571
      Likes
      49
      Thanks, slash.
      How do I run it in a window instead of terminal?

    20. #70
      Ex Tech Admin Achievements:
      Created Dream Journal Tagger First Class Veteran First Class 10000 Hall Points Populated Wall Referrer Gold Made lots of Friends on DV
      slash112's Avatar
      Join Date
      Nov 2008
      Gender
      Location
      Sunny Scotland
      Posts
      5,113
      Likes
      1567
      DJ Entries
      29
      Yea... I was wondering the same thing.

      I want to learn how to make a GUI. It isn't necessary at this stage though, anyway.

    21. #71
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by ninja9578 View Post
      You should also loop into while loops and for loops.

      Code:
      int a = 50;
      do{
         std::cout << "I'm inside the loop " << a++ << std::endl;
      } while (a < 10);
      Code:
      int a = 50;
      while (a < 10){
         std::cout << "I'm inside the loop " << a++ << std::endl;
      }
      Have one but very important difference, see if you can figure out what it is
      The difference has to do with where the check is made. In the first bit of code, the check doesn't happen until after what's inside the loop has been done, therefore, it ALWAYs gets done at least once, the second piece of code does the check beforehand, so it may never get called

      Stick with terminals for now, I'll show you how to make a window a little later.

    22. #72
      .. / .- –– / .- .-. guitarboy's Avatar
      Join Date
      Sep 2008
      LD Count
      Over 9000
      Gender
      Location
      Homeward Bound
      Posts
      1,571
      Likes
      49
      alright, I wrote a program that gives you the circumference of a circle after you put in the circumference and the approximate of pi.
      How can I make it simpler, i.e; tell it that the variable p is 3.14, without you having to put it in.
      Code:
      #include <iostream>
      using namespace std;
      
      int main()
      {
           int r, p, Total;
      
           cout << "Enter radius and pi approximate here... "
      
           ;cin >> r >> p;
      
           Total= r * r * p;
      
           cout << "Circumference is " <<Total << endl;
      
           return 0;
      }
      and how do I run it in a window, not terminal

    23. #73
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by guitarboy View Post
      alright, I wrote a program that gives you the circumference of a circle after you put in the circumference and the approximate of pi.
      How can I make it simpler, i.e; tell it that the variable p is 3.14, without you having to put it in.

      and how do I run it in a window, not terminal
      Code:
      #include <iostream>
      using namespace std;
      
      #define PI 3.141592654357
      
      int main()
      {
           float r, Total;
      
           cout << "Enter radius here... "
      
           cin >> r;
      
           Total= r * 2 * PI;
      
           cout << "Circumference is " <<Total << endl;
      
           return 0;
      }
      First off, ints are just integers, you need decimals for this, so we use float instead. Also, your formula was wrong Circumfrance = pi time diameter, you were calculating area. lol.

      #define is what's called a macro, it's not real code. When the compiler compiles your source code, the first thing that it does, it copies and pastes macros. So when the code gets compiled, the literal value of pi gets replaced at all occurrences of PI. It is standard practice to keep definitions in caps, although not necessary.
      Last edited by ninja9578; 01-11-2010 at 01:18 AM.

    24. #74
      Ex Tech Admin Achievements:
      Created Dream Journal Tagger First Class Veteran First Class 10000 Hall Points Populated Wall Referrer Gold Made lots of Friends on DV
      slash112's Avatar
      Join Date
      Nov 2008
      Gender
      Location
      Sunny Scotland
      Posts
      5,113
      Likes
      1567
      DJ Entries
      29
      Nice, guitarboy. It's funny how different I would do it from that. It's amazing the amount of possibilities for one single purpose.

      Also, you don't really need a window yet, do you.

    25. #75
      .. / .- –– / .- .-. guitarboy's Avatar
      Join Date
      Sep 2008
      LD Count
      Over 9000
      Gender
      Location
      Homeward Bound
      Posts
      1,571
      Likes
      49
      Quote Originally Posted by ninja9578 View Post
      Code:
      #include <iostream>
      using namespace std;
      
      #define PI 3.141592654357
      
      int main()
      {
           float r, Total;
      
           cout << "Enter radius here... "
      
           cin >> r;
      
           Total= r * 2 * PI;
      
           cout << "Circumference is " <<Total << endl;
      
           return 0;
      }
      First off, ints are just integers, you need decimals for this, so we use float instead. Also, your formula was wrong Circumfrance = pi time diameter, you were calculating area. lol.

      radius * radius= diameter, times pi

      #define is what's called a macro, it's not real code. When the compiler compiles your source code, the first thing that it does, it copies and pastes macros. So when the code gets compiled, the literal value of pi gets replaced at all occurrences of PI. It is standard practice to keep definitions in caps, although not necessary.
      Also, you don't really need a window yet, do you.
      it would be nice to know how to do it.
      And color it.
      and change text color.
      etc.

    Page 3 of 7 FirstFirst 1 2 3 4 5 ... LastLast

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •