Results 1 to 4 of 4

Thread: No idea what to do next

  1. #1
    Join Date
    Apr 2009
    Posts
    3

    sad No idea what to do next

    K so I'v been trying for the past four days to sort this program out, i'll admit i'm not particularly good at programming, i'm really new at it and I'm struggling through my uni course, i've written as much of this program as i can but i don't know what to do next.

    Here's what i'v got

    #include <iostream>
    #include <cmath>

    using namespace std;

    // The precondition statement indicates what
    // must be true before the function is called.
    // The postcondition statement indicates what
    // will be true when the function finishes its work.

    int largest_prime_factor (int a);
    // precondition: a > 0
    // postcondition: the function returns to the largest prime factor of a

    int squared_digit_length (int a);
    // precondition: a > 0
    // postcondition: the function returns to the square digit length starting from a

    // define other functions if necessary

    int main ()
    {
    char ch1, ch2; // ch1 is used for the first letter of the first name
    // ch2 is used for the first letter of the surname
    int n1, n2, n3, n4, n5; // used for the 5 steps of the task

    cout << "Enter your first name and surname: " << flush;
    cin >> ch1; // read the first letter of the first name
    cin.ignore(100,' '); // ignore the rest of the character in the first name
    cin >> ch2; // read the first letter of the surname

    n1 = static_cast<int>(ch1);

    n2 = static_cast<int>(ch2);

    n3= squared_digit_length(n1);

    n4 = squared_digit_length(n2);

    n5 = n4 + n5;

    cout << n1 << n2 << endl;


    return 0;
    }


    int square_digit_length(int a)

    {
    int ones, tens, hundreds;
    float floatOnes, floatTens, floatHundreds;
    int num = 0;
    int a;

    while (a = 4)
    {
    if (a >= 100)
    tens = (a/100)%10;
    else tens = a/10;

    ones = a%10;
    hundreds = a/100;
    floatOnes = pow((float)ones,2);
    floatTens = pow((float)tens,2);
    floatHundreds = pow ((float)hundreds,2);
    num++;
    a= (floatOnes+floatTens+floatHundreds);

    }


    }


    basically the program has to take in a first and last name, convert the first letters of the name into thier ASCII values, calculate the squared digit length of both letters, then output those lengths and the largets prime factor of those lenghts added together.

    I know i need to use return functions but i don't really understand how they work and i need a function for the largest prime factor.
    i'd really apreciate it if anyone could help, and would love it if people could explain their suggestions so that i actually learn something from it. Thanx C:

  2. #2
    Join Date
    Apr 2009
    Posts
    3

    Re: No idea what to do next

    It's in C++ by the way, sorry forgot to add that

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: No idea what to do next

    Every character has a different number under which it is stored on your computer. There are 256 different ASCII codes (the possible values a byte can hold), that is why a character takes one byte.


    Code:
    // Transform a word into ASCII code
    
    #include <iostream>
    using namespace std;
    int main()
    {
        char word[32];
        int x = 0;
        cout << "Please enter the word (maximum 32 characters):\n";
        cin >> word;
        cout << "The ASCII for this word is:\n";
        while (word[x] != '\0')    // While the string isn't at the end...
        {
            cout << int(word[x]);    // Transform the char to int
            x++;
        }
        cout << "\n";
        return 0;
    }
    With the while loop trough the array and convert every character using int(word[x]) to its ASCII value. If we hit at the end of the string, the while loop returns false and ends.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: No idea what to do next

    I think the functions that you have created must return the values to the main function from where it is called. So, using return functions is extremely important.

    Also, check the compiling errors which you are getting. That will best tell you where you are going wrong...

    goodluck

Similar Threads

  1. using Idea 3g net with Airtel
    By nimesh.tt in forum India BroadBand
    Replies: 3
    Last Post: 06-09-2013, 12:00 PM
  2. Going to buy a new PS3.. Good Idea or a bad one??
    By VazV in forum Portable Devices
    Replies: 4
    Last Post: 12-08-2011, 08:04 PM
  3. Idea 666 IPL Dhamaka
    By Sitesh in forum India BroadBand
    Replies: 1
    Last Post: 02-06-2011, 05:59 AM
  4. Idea SIM card Now at Rs. 11
    By Saku in forum India BroadBand
    Replies: 8
    Last Post: 29-11-2010, 05:49 PM
  5. Soulcalibur IV DLC idea
    By neuro in forum Video Games
    Replies: 2
    Last Post: 25-08-2009, 06:58 PM

Tags for this Thread

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
  •  
Page generated in 1,713,859,908.95962 seconds with 16 queries