Need some help ....

This is a discussion on Need some help .... within the General Chat board part of the General category; Hello guys... Usually I am visiting this site to get some nice hacks , or to read some nice discussions... ...

Results 1 to 5 of 5
  1. #1
    MmbOkO is offline Newbie
    Array
    Join Date
    Mar 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    0
    Reputation
    0

    Need some help ....

    Hello guys... Usually I am visiting this site to get some nice hacks , or to read some nice discussions... but this time it is different... I have one big problem. I had to make project on "C" programming language for the university... but when I gave it to the teacher... he told me that he will let me pass only if i fix this program:

    #include <stdio.h>

    main()
    {
    int n;
    cin >> n;
    if (n < 0) return 1;
    int sum = 0;
    int i = 0;
    while (i <= n) sum += i*i;
    cout << sum;
    return 0;
    }

    I have no idea how to fix it .. it seems ok to me . Please someone that is fammiliar with "C" programming language help me ! If i dont fix this program I won't pass... Please fix it guys !
    Sorry that I am bothering you with this kind of things... but I dont know who else to ask

    Thanks in advance ! Big thanks!


  2. #2
    MmbOkO is offline Newbie
    Array
    Join Date
    Mar 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    0
    Reputation
    0
    pls guys ... someone assist me ! pls pls pls !

  3. #3
    <GM>Bumblebee's Avatar
    <GM>Bumblebee is offline I'm The Good Bee :)



    Array
    Join Date
    May 2010
    Location
    Palmdale,CA
    Posts
    1,912
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    12
    Reputation
    1146
    I think this would belong in development not general chat O.o

    Click here To see all my Tutorials and get Help.

  4. #4
    YourName's Avatar
    YourName is offline THE ONE AND ONLY DARK KNIGHTY


    Array
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    1,553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    15
    Reputation
    1088
    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    
    int main()
    {
        char* nn;
        cin >> nn;
        int i;
    
        //Loop through the whole char* and check if a char is not a digit.
        for (i = 0; i < strlen(nn); i++)
            if (!isdigit(nn[i]) return 0;
    
        //atoi = Array to integer, it converts our char* to an integer
        int n = atoi(nn), sum = 0;
        if (n < 0) return 0;
    
        for (i = 0; i < n; i++)
            sum += i*i;
    
        cout << sum;
        return 0;
    }
    Like this, probably?
    If we don't know what he wants to get fixed, it's kinda difficult to help you.
    Also, just as Bumblebee said, this belongs into the Development section.
    Last edited by YourName; 10-09-2010 at 01:57 PM.
    Providing you with foolish stuff since 2007.

  5. #5
    MmbOkO is offline Newbie
    Array
    Join Date
    Mar 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rep Power
    0
    Reputation
    0
    Task: Input an integer number n and output the sum: 1+22+32+...+n2. Use input validation for n to be positive.

    this is what he wants .... Is this code correct for this task ?

    P.S. Sorry that the threat is not in the correct section.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •