Thread: Please help me get started!

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    22

    Unhappy Please help me get started!

    Ahhhh...well I got this homework assignment for the weekend and I really don't understand loops and how they work. If anyone could please point me in a direction to get started on this assignment, I would greatly appreciate it!!

    Assignment:

    http://www.cs.uwm.edu/classes/cs201/.../05/05/05.html
    (Program #10)

    Thanks in advance!

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Part 1 of program 10 involves no loops.

    Code:
    Prompt the user for an integer and read it.
    Simple cout then cin

    # Display the data headings.
    cout << "Number Div by 2 Div by 3 Div by 5 Square SqRoot";

    # Display the data.
    sqrt is defined in cmath
    to determine divisibility the method is this

    if (NUMBER % NUMBER_DIVISIBLE_BY? == 0)
    cout << "Yes";

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    22
    Thanks, but I think I need more of a basic walkthrough...like how to create the functions an stuff like that.

    If any of you guys could help, I would really appreciate it.

  4. #4
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    functions are easy to understand if you understand what a parameter is.
    When no one helps you out. Call google();

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    22
    Alright does anyone know what I should do from here? I have no idea if this is right...I keep getting this error when I try to compile it.

    Code:
    Undefined                       first referenced
     symbol                             in file
    displaySqRoot(int)                  /var/tmp//ccPzasRe.o
    displayData(float)                  /var/tmp//ccPzasRe.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status

    Code:
    #include <iomanip>
    #include <iostream>
    #include <cmath>
    
    using namespace std;
    
    //Function prototypes.
    int userPrompt();
    void displayHeadings();
    void displayData(float x);
    void displaySqRoot(int x);
    
    //Main function.
    int main()
    {
      int user_int;
      user_int=userPrompt();
      displayHeadings();
      displayData(user_int);
      displaySqRoot(user_int);
      return 0;
    }
    
    //Function definitions.
    
    //Get number from user.
    int userPrompt()
    {
      int value;
      cout << "Please enter a number: ";
      cin >> value;
      return value;
    }
    
    //Display headings.
    void displayHeadings()
    {
      cout << endl << "\tNumber\tDiv by 2\tDiv by 3\tDiv by 5\tSquare\tSqRoot\tPrime" <<endl;
    }
    
    
    //Display data.
    void displayData(int value)
    {
      cout << "\t" << value << "\t";
      if((value%2) == 0.0) cout << "Yes\t\t";
      else cout << "No\t\t";
      if((value%3) == 0.0) cout << "Yes\t\t";
      else cout << "No\t\t";
      if((value%5) == 0.0) cout << "Yes\t\t";
      else cout << "No\t\t";
    }
    
    //Display square root.
    void displaySqRoot(float value)
    {
      cout << value*value << "\t";
      if(value>=0.0) cout << setprecision(3) << sqrt(value) << endl;
      else cout << "ERROR" << endl;
    }

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Compare the function prototypes (at the top of the file) with the function definitions (at the bottom) for the two functions that get the error and see if you notice what the problem is.

    BTW, unless your class or instructor tells you otherwise, you should be using double instead of float.

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Thanks, but I think I need more of a basic walkthrough...like how to create the functions an stuff like that.
    Hmmm...and suddenly all the code magically appears. Let see...I'll lay 50:1 you didn't write that code.

  9. #9
    Registered User
    Join Date
    Feb 2006
    Posts
    22
    Ah, I see Daved...my float and int's were switched around...Thanks!

    And 7stud, your odds were incorrect....that was quite a n00bish phrase I said. I was really wondering how to set up the problem...not how to write functions.



    Anyway, does anyone have any tips on finding prime numbers? I'm stuck. It's part two of the assignment link above.

    Thanks!
    Last edited by the_lumin8or; 03-12-2006 at 11:55 PM.

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Anyway, does anyone have any tips on finding prime numbers?
    1) Write down what calculations you have to make to determine if 17 is a prime number.
    2) Write down what calculations you have to make to deterimine if 18 is a prime number.
    3) Start writing some code to mimic the calculations you went through.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Anyway, does anyone have any tips on finding prime numbers?
    http://www.google.com/search?q=sieve+eratosthenes

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help getting started..matrices
    By BobDole11 in forum C Programming
    Replies: 7
    Last Post: 11-15-2008, 09:51 PM
  2. Help getting started :(
    By blackocellaris in forum C Programming
    Replies: 4
    Last Post: 11-05-2006, 06:50 PM
  3. Getting started
    By panzeriti in forum Game Programming
    Replies: 3
    Last Post: 06-28-2003, 10:13 AM
  4. How to get started?
    By anoopks in forum Linux Programming
    Replies: 0
    Last Post: 01-14-2003, 03:48 AM
  5. Need help getting started
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2001, 11:08 PM