• Lucid Dreaming - Dream Views




    Results 1 to 25 of 165

    Hybrid View

    1. #1
      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

    2. #2
      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...

    3. #3
      .. / .- –– / .- .-. 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?

    4. #4
      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.

    5. #5
      .. / .- –– / .- .-. 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

    6. #6
      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.

    7. #7
      .. / .- –– / .- .-. 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.

    8. #8
      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
      radius * radius= diameter
      plus, not times
      (\_ _/)
      (='.'=)
      (")_(")

    9. #9
      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
      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.
      I understand why you want to get into GUI stuff, but trust me, at this stage it'd just confuse you

      You've got to get a proper handle (no pun intended) on the language before delving into external APIs

      At present, you're doing really simple maths with C++
      you've yet to grasp the more advanced concepts needed for GUI apps

      We haven't even covered stuff outside main() yet
      let alone classes, templates, memory allocation, STL, etc. etc.

      Walk, then run
      But right now, we're still bobing about in the sea, before we developed legs
      (\_ _/)
      (='.'=)
      (")_(")

    10. #10
      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.

    11. #11
      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.

    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
    •