program problem

square root problem for hanosh

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 2000 Views - Last Post: 05 February 2002 - 04:15 PM Rate Topic: -----

#1 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

program problem

Posted 04 February 2002 - 05:21 PM

I'm having a problem with my program for Mr. Hanosh.  It's for program 2, formula game.  I can't figure out how to do the square root or the prime/composite part.  I have no idea how to do the square root.  The only way I could think to do the prime/composite part was a big if/then statement... but that would be called "Junk Code".  Is there a better way?  
Is This A Good Question/Topic? 0
  • +

Replies To: program problem

#2 Quik  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2
  • View blog
  • Posts: 3,750
  • Joined: 06-March 01

Re: program problem

Posted 04 February 2002 - 05:42 PM

Didnt you need help w/ program 1 also? *nods..
hehhe, I wish i could help, but I know 0 bout C++
Was This Post Helpful? 0
  • +
  • -

#3 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,409
  • Joined: 21-March 01

Re: program problem

Posted 04 February 2002 - 05:51 PM

ok, heres some hints:

in your book, look up "sqrt" its a function, really easy to use.

for prime composite, this is where your algebra skills come in. there are 4 numbers, which you can use in conjunction with the % operator to figure out if its prime or composite, think a while on that one.

Was This Post Helpful? 0
  • +
  • -

#4 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 04 February 2002 - 06:47 PM

ok, i'll look up sqrt... but would this work?  For even/odd i tried an if/else statement with if as (num/2 >= 1).  I thought it'd work, but i didn't account for decimals.  How can i account for decimals?  By saying (num/2 >= 1) and adding something saying just as long as it's not a floating number?
Was This Post Helpful? 0
  • +
  • -

#5 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,409
  • Joined: 21-March 01

Re: program problem

Posted 04 February 2002 - 07:03 PM

ok, dont use division for this part. mudolos. %  << use that symbol. its the key.
Was This Post Helpful? 0
  • +
  • -

#6 Teckwiz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 120
  • Joined: --

Re: program problem

Posted 04 February 2002 - 08:19 PM

#include<math.h>
#include<math.h>
#include<math.h>
#include<math.h>
#include<math.h>
#include<math.h>
#include<math.h>


Thats all i have to say

Was This Post Helpful? 0
  • +
  • -

#7 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 04 February 2002 - 08:26 PM

thanks dragon, i have <math.h>.  supersloth, i'll try looking up the %.  a question, though.  I found sqrt in chapter 9, and read about it, but how do i apply it?  do i put in the #include sqrt, or do i apply it as an actual function like "void main" only "void sqrt"?  I tried putting it in {cout << "the square root to" << num << "is" << double sqrt(double num)'
';}, and that didn't work.  the double was highlighted in blue.  basically, how do those functions work?  
Was This Post Helpful? 0
  • +
  • -

#8 Teckwiz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 120
  • Joined: --

Re: program problem

Posted 04 February 2002 - 08:33 PM

i don't have the book any mo'

but its like
double sqrt(double num)

but not exactly


Was This Post Helpful? 0
  • +
  • -

#9 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 04 February 2002 - 08:37 PM

when did you have mr hanosh?  do you put it in the cout or something?
Was This Post Helpful? 0
  • +
  • -

#10 Teckwiz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 120
  • Joined: --

Re: program problem

Posted 04 February 2002 - 08:40 PM

Second Semester last year, and first semester this year,

and you can, or you can stick it into a variable

Was This Post Helpful? 0
  • +
  • -

#11 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 04 February 2002 - 08:44 PM

how would i put it into a variable?  would i say int sqrt, or int double sqrt(double num), or what?
Was This Post Helpful? 0
  • +
  • -

#12 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,409
  • Joined: 21-March 01

Re: program problem

Posted 04 February 2002 - 09:16 PM

cout << "the square root is " << sqrt(num);


Was This Post Helpful? 0
  • +
  • -

#13 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 05 February 2002 - 03:23 PM

thanks, but i don't need that anymore... i figured it out already in class.  but how can i do the prime/composite.  I tried using an if/else statement, but that didn't work.  Someone said i should use a for loop.  which would be best and should i inculde the % modulus?
Was This Post Helpful? 0
  • +
  • -

#14 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,409
  • Joined: 21-March 01

Re: program problem

Posted 05 February 2002 - 04:03 PM

num % whatever

its in your book, and your notes. and you dont need a for loop. your a whole program only needs one loop, and thats to ask if they are playing again.

Was This Post Helpful? 0
  • +
  • -

#15 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 05 February 2002 - 04:07 PM

so what does that mean?  use an if/then statement w/ modulous and forget the for loop?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2