• Lucid Dreaming - Dream Views




    Results 1 to 25 of 165

    Hybrid View

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

    2. #2
      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;
      }
      (\_ _/)
      (='.'=)
      (")_(")

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

    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
      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

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

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

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

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

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

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

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

    12. #12
      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
    •