Need an algorithm

Reply

Join Date: Nov 2007
Posts: 44
Reputation: c++ prog is an unknown quantity at this point 
Solved Threads: 1
c++ prog's Avatar
c++ prog c++ prog is offline Offline
Light Poster

Need an algorithm

 
0
  #1
Nov 17th, 2008
hi, we have a simple program here that states like this:
  1. input >= 10
  2.  
  3. ex: 12
  4.  
  5. 1 Square Sqrt Cube Fouthroot
  6. 2 - - - -
  7. 3 - - - -
  8. 4
  9. 5
  10. 6
  11. 7
  12. 8
  13. 9
  14. 10
  15. 11
  16. 12

i made the code already but I still can't find a solution the solutions from 1 to 11.. my code only displays the results for the 12... I know this can be solved pretty easily by some loops, but for a strange reason,I can't find the right algorithm! lol! i just need an algorithm and just leave the programming to me..tnx
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Need an algorithm

 
0
  #2
Nov 17th, 2008
post your code, its hard to see what you are having trouble with
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 44
Reputation: c++ prog is an unknown quantity at this point 
Solved Threads: 1
c++ prog's Avatar
c++ prog c++ prog is offline Offline
Light Poster

Re: Need an algorithm

 
0
  #3
Nov 17th, 2008
  1. /*
  2.  
  3.  */
  4.  
  5. package alejo_a1;
  6.  
  7.  
  8. import java.util.Scanner;
  9. public class java {
  10.  
  11. /**
  12.   * @param args the command line arguments
  13.   */
  14. public static void main(String[] args) {
  15. double n;
  16. Scanner input = new Scanner(System.in);
  17.  
  18. System.out.print("Enter integer to be solved: ");
  19. n = input.nextDouble();
  20. //for (double i=0; i >= 10; i++)
  21. //if (n >= 10)
  22. //{
  23. //{
  24. // for(int i = 1; i >=10; i++)
  25. //{
  26. // i = n;
  27. System.out.println("The Square of " + n + "= " + Square(n));
  28. System.out.println("The Square Root of " + n + "= " + SquareRoot(n));
  29. System.out.println("The Cube of " + n + "= " + Cube(n));
  30. System.out.println("The Fourth Root of " + n + "= " + FourthRoot(n));
  31. //}
  32. //}
  33. //}
  34. }
  35.  
  36. static double Square( double Squ)
  37. {
  38. double result = 0;
  39. int i =0;
  40. result= Math.pow(Squ,2);
  41. // for (;i >= 10; i++)
  42.  
  43. return result;
  44.  
  45. }
  46.  
  47. static double SquareRoot( double TwoRoot)
  48. {
  49. int i =0;
  50. double result2 = 0;
  51. result2 = Math.pow(TwoRoot, (1/2));
  52. while(i >= 10)
  53. {
  54.  
  55. System.out.println("Square Root of" + TwoRoot + "= " + result2);
  56. i++;
  57. }
  58. return result2;
  59.  
  60. }
  61.  
  62. static double Cube( double CubeX)
  63. {
  64. int i =0;
  65. double result3 = 0;
  66. result3 = Math.pow(CubeX, 3);
  67.  
  68. do{
  69.  
  70.  
  71. //System.out.println("Cube of" + CubeX + "= " + result3);
  72. }while(i >= 10);
  73. return result3;
  74. }
  75.  
  76. static double FourthRoot( double Fourth)
  77. {
  78. int i = 0;
  79. double result4 =0;
  80. result4 = Math.pow(Fourth, 0.25);
  81. for (; i >= 10; i++)
  82. {
  83.  
  84. System.out.println(" Fourth Root of" + Fourth + "= " + result4);
  85. }
  86. return result4;
  87. }
  88.  
  89. }

it's a bit messy
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Need an algorithm

 
0
  #4
Nov 17th, 2008
you have your for loop commented out

for startes make these changes
  1. int n;
  2.  
  3. n=input.nextInt();
  4.  
  5. for(int i=0; i<= n; i++){
  6. //do your println's here using i instead of n
  7. //if you need a double from an int use
  8. (double)i;
  9. }
Last edited by dickersonka; Nov 17th, 2008 at 11:13 am.
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC