Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 527 528 [529] 530 531 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 883060 times)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7920 on: September 23, 2015, 08:45:25 pm »

I have a Python wsgi app running under apache. When I try to use the Requests library's get() function it segfaults spectacularly, with no error message or anything. Strange thing is, it doesn't crash when ran stand-alone from the terminal.

How do I debug this :(
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7921 on: September 23, 2015, 08:47:53 pm »

I really hate if statements

That's a bit premature. I'm about 100% sure that your problem is with something that isn't actually if statements.

Thanks for the help man. I appreciate it.

Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7922 on: September 23, 2015, 08:50:13 pm »

Same problem as before. It's the same calculator I need to make but i'm trying to make it so that I can get the answers I need before making it stupid proof (i.e giving input validations in) since I think it'll help me later.
Okay, some minor advice:
Pi should be a constant if it doesn't change. Declare "const double PI = 3.14;" above main. "Pie" is not a meaningful variable name, and is bad form.
You don't need exponentC anymore. "pow(radiousC, 2)*pie" can be replaced with "radiousC*radiousC*pie" (unless the instructor is requiring you to use <cmath> functions.)
You should be using "else if", or your code is wasting time checking the other conditions even after it's found the right one.
You shouldn't be using {} for no reason where you're outputting the area. I'm 90% sure this gives a compiler error. You're missing the > 0 check there.

Any slight efficiency gains from these changes is secondary. It's just proper programming form.
« Last Edit: September 23, 2015, 08:53:21 pm by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7923 on: September 23, 2015, 08:51:15 pm »

Same problem as before. It's the same calculator I need to make but i'm trying to make it so that I can get the answers I need before making it stupid proof (i.e giving input validations in) since I think it'll help me later.

Spoiler: the code (click to show/hide)

I really hate if statements and unfortunately I think my class is stepping into high gear mode.

I compiled the code you posted here with g++ and it seems to work a-okay, except I had to comment out the "system" line (which I assume is referencing a part of the code that you haven't posted). What exactly was the issue? If it's preventing negative input, consider that you can have an if statement inside of another if statement. For example:

Code: [Select]
if (userRequest == 1)
{

    cout << "Hello user: Please input the radious of your circle. " << endl;

    cin >> radiousC;


    if(radiousC > 0)
    //Above is needed for the submenu of the circle which takes radious and later checks it.
    {
        //in here is the actual forumula when the radious is inputed correctly.
        cout << "This is the area of your circle: " << endl << pow(radiousC, 2)*pie << endl;
    }


}

And consider what Bumber says, as well. "It compiles" doesn't necessarily mean that you're done programming.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7924 on: September 23, 2015, 08:56:53 pm »

I compiled the code you posted here with g++ and it seems to work a-okay, except I had to comment out the "system" line (which I assume is referencing a part of the code that you haven't posted).
It's a Windows-specific hack. cin.get() is considered the proper way to pause. Or better yet find out how to get your IDE to not close the terminal.
« Last Edit: September 23, 2015, 09:00:25 pm by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7925 on: September 23, 2015, 09:01:38 pm »

Uh, 3man.   Not to trivialize your problem, but it's spelled radius, not radious.
And input, not inputed.
And length not lenght.
Sorry, my chronic spellcheck is acting up.
...Oh, and the mathematical constant is pi, and is 3.14159265...More digits is probably better unless you have some sort of hard limit on length.  The user can cut off digits, but can't add them.

Okay, now to look at the code.
Full disclosure, I only know Java.
Aaand it looks like it should work.  Which is somewhat confusing because you say it doesn't.
Yeah, the if statements look fine.

...Are those brackets around the circle area output (cout  << "This is the area....") supposed to be there?

But yeah, what Bumber said.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7926 on: September 23, 2015, 09:01:51 pm »

Hang on, your problem is you want it to prevent the user supplying a negative number?

What you'll want to do for that is add another if statement after the user supplies data. You've even got the code bracketed properly. I'm assuming you haven't got to writing your own functions or anything like that.

Code: [Select]
if (userRequest == 1)
   {
      cout << "Hello user: Please input the radious of your circle. " << endl;
      cin >> radiousC;
      if(radiousC >= 0)
      //Above is needed for the submenu of the circle which takes radious and later checks it.
         {
         //in here is the actual forumula when the radious is inputed correctly.
         cout << "This is the area of your circle: " << endl << pow(radiousC, 2)*pie << endl;
         }
      else
         {
         cout << "Please input a positive number.";
         }
   }

Remember, an if statement is you telling your computer "If this is true, do the thing in the following brackets." Programs execute from top to bottom, as a series of instructions. Your computer doesn't know about any statements lower down until it gets there. When they hit an if statement, they check whether the condition they're given is true; if so, they execute the code inside the following brackets. If not, they skip it. You can put if statements inside other if statements - this is like saying "If Bob gets to work today, he needs to do all these things, and if he finishes them, here's this other thing he needs to do."

This sort of pattern, where you put something like an if statement inside another example of itself, is called "nesting". It applies to a lot of other statements you can make, too. Indentation is just a way of keeping track of it in C++. You could actually delete all of the indentations in your code and it would work just fine (though this isn't true for all languages). It's just there so you can read it - that way you can easily tell how many conditions need to be passed to get to some piece of code, and which pieces go together in different cases.

Speaking of readability, I would recommend working on your spelling - I know this sounds nitpicky, since the computer doesn't know correct spelling or care, but it will make it easier for yourself and others to read your code again later on, and it'll save you having to remember your own notation for your own code and the more common spelling when you read anyone else's.

EDIT: ninjas, also semicolon and i wrote the condition backwards because i'm a dumb
« Last Edit: September 23, 2015, 09:19:54 pm by Bauglir »
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7927 on: September 23, 2015, 09:13:38 pm »

Yeah, like
Code: [Select]
boolean didtheprogramfinish = false;
if(programchoice==1){
     while(didtheprogramfinish == false){
     int radius = 0;
     //or not, I really don't have a clue what your variables have to
     //be like.  Like I said, I only know Java.  Sorry.  But anyway.
     //...In fact, it might be an idea, if you can keep the thing
     //from blowing up when it isn't, to not initialize radius.
     //Then again, things with radius of zero are also wrong.
     //You're probably good.  Any who back to actual code.
     cin >> radius;
          if(radius>0){
               //math bit here
               //print the output
               didtheprogramfinish = true;
          }
          else {
          //error message
          }
     }
}
I warrant nothing about the actual usability of this code.  Typing on mobile, plus basically having to infer everything, doesn't a confident coder make.
« Last Edit: September 23, 2015, 09:16:45 pm by TheBiggerFish »
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7928 on: September 23, 2015, 09:18:52 pm »

Yeah, though I'm gambling he's not covered while loops (for reference, they're pretty much what they sound like - they're if statements that repeat the bracketed code until their condition stops being true - hence, while(True) repeats forever).

also i haven't ever written c++, just c, but i don't think they vary much in the relevant bits other than the format for putting stuff in or out

but if i messed it up that's why
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7929 on: September 23, 2015, 09:22:35 pm »

No I haven't gotten into functions yet. I'm going to assume they make life easier. I'm suppose to be using Cmath and to be honest I whitewashed on my code again since from the first comment it looked like no one was going to help me. Sorry I assumed ahead after 'your problem isn't this its *input reason*'.

I can do if statements fine and I know how they work but for some reason I can't get my else if statements to plug in with the rest.

For example:
Spoiler (click to show/hide)

Tried to make it with less spaces this time.

In here I find that I can get the right response to my negative inputs and positive inputs for the circle. However, should I click on option 2 for rectangle I'm asked for a radius followed by length and width. This is probally due to how if is being used in option 1 and 2.

if (menuoption =1){
....}

//followed by

if (menuoption = 2) {
...}

Which gives me code from both instead of the one I asked for.

ninja'd.

I have not covered loops and when I asked my tutors they said that's for later and to focus on now. I'm known to try to get ahead while not finishing up my plate. Problems arise unfortunately.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7930 on: September 23, 2015, 09:26:52 pm »

>if (menuOption = 1)

if (menuOption == 1)

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7931 on: September 23, 2015, 09:36:26 pm »

>if (menuOption = 1)

if (menuOption == 1)



Clarification needed. I just made both menu options to equal 1 and 2.

It works but now their seems to be a "break" where it'll run the "sorry no negatives" line of code and then length and width.

Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7932 on: September 23, 2015, 09:40:10 pm »

This is really weird and annoying.

I've traced the ultimate source of the crash to... the python standard library?

Line 1421 of urllib.py has
proxy_settings = _get_proxy_settings()
and this comes from another scarily-named library _scproxy. I don't understand why the standard library is crashing when embedded as a wsgi application...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7933 on: September 23, 2015, 09:42:41 pm »

If menuoption isn't set to 1, what does radiusC equal when it reaches that part in the code?

What do you mean?

Radius is set to whatever the user inputs it to be in the cin line I have under menuOption 1. Or is there something else your trying to tell me?

Found a huge error now that when I go for option 2 it breaks fretting over the radius. When I go back in the line of code for "sorry no negatives numbers" is used and then it simply runs the option 2 lines of code as instructed.

Logged

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7934 on: September 23, 2015, 09:52:14 pm »

You must use the operator ==, not =, for conditions.

= is the assignment operator. What's happening is that your code is that you get to the if statement, then it evaluates the condition you give it. The operator returns 1 because it succeeded, and C++ (at least if C is anything to go by) treats any nonzero value as True when you use it as a boolean (a boolean is a data type that can only have the values True or False). At least that's what I think the reason for that behavior is, but the thing I know is that you'll get wacky results with this typo.

== is the comparison operator, and it returns True if the two things you hand it are equal, and False otherwise.

You had it right the last time, so I don't know why you changed it.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.
Pages: 1 ... 527 528 [529] 530 531 ... 796