Like Tree11Likes

I'm new taking my 1st class, and I am having trobble with my homework.. help please!

This is a discussion on I'm new taking my 1st class, and I am having trobble with my homework.. help please! within the C Programming forums, part of the General Programming Boards category; Originally Posted by Cess also dunno if this is a factor but I"m using dev C No you're not... you're ...

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Cess View Post
    also dunno if this is a factor but I"m using dev C
    No you're not... you're using DevC++ ... a whole different language. There is no Dev C.

    Also you should be aware that compiler and IDE have been abandonware for most of a decade. The compiler is hopelessly out of date and the guy who wrote the IDE is noplace to be found.

    I think, you should give serious consideration to getting onto a purely C compiler, C-99 compliant, and a new IDE that is up to date...
    I generally suggest Pelles C but there are others you can use.

  2. #17
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Double Header! ... Hi Quzah...

  3. #18
    Registered User Cess's Avatar
    Join Date
    Sep 2011
    Posts
    55
    ops... that was silly of me...that happen cuz I started over and it automatically had that part and I didn't double check it sorry..... I'm extremely new so ya sorry.
    lets try this again..... why am I still getting errors...

    Code:
    #include <stdio.h>
    #include <math.h> 
    
    int main()
    {    
         {int number;
         printf(" enter a positive number between 1 and 10:");
         }
         {if( (number < 1) || (number > 10) ) 
         printf("The number is out of range. (1-10)\n");
         }
    system("PAUSE");
    return 0;
    }

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Cess View Post
    ops... that was silly of me...that happen cuz I started over and it automatically had that part and I didn't double check it sorry..... I'm extremely new so ya sorry.
    lets try this again..... why am I still getting errors...
    Because you aren't paying attention to what you are doing, and are really just throwing random bits of code in trying to get lucky:
    Code:
    #include <stdio.h>
    #include <math.h> 
    
    int main()
    {    
         {int number;
         printf(" enter a positive number between 1 and 10:");
         }
         {if( (number < 1) || (number > 10) ) 
         printf("The number is out of range. (1-10)\n");
         }
    system("PAUSE");
    return 0;
    }
    More does not mean better. Everything inside a pair of braces goes out of scope as soon as you hit the closing brace. All the inner vanishes when you hit the closing braces.


    Quzah.
    Last edited by quzah; 09-24-2011 at 05:35 PM. Reason: color tag chaos
    Salem likes this.
    Hope is the first step on the road to disappointment.

  5. #20
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Cess View Post
    ops... that was silly of me...that happen cuz I started over and it automatically had that part and I didn't double check it sorry..... I'm extremely new so ya sorry.
    lets try this again..... why am I still getting errors...

    Code:
    #include <stdio.h>
    #include <math.h> 
    
    int main()
    {    
         {int number;
         printf(" enter a positive number between 1 and 10:");
         }     
         {if( (number < 1) || (number > 10) ) 
         printf("The number is out of range. (1-10)\n");
         }system("PAUSE");
    return 0;
    }
    Because you are using the rules of scope incorrectly...

    Code:
        {int number;     <--- you start a new scope here
         printf(" enter a positive number between 1 and 10:");
         }                      <-- you end it here, number is destroyed.
         {if( (number < 1) || (number > 10) )    <--- you start another scope here but number is unknown
         printf("The number is out of range. (1-10)\n");
         }                                         <--- you end the second scope here
    Yes, that's right, those curly braces are active parts of the software, not merely window dressing.

    try this...
    Code:
    #include <stdio.h>
    #include <math.h> 
    
    int main()
    {    
         int number;
         printf(" enter a positive number between 1 and 10:");
    
    scanf("%d",&number);
         
         if( (number < 1) || (number > 10) ) 
            printf("The number is out of range. (1-10)\n");
         
    
    return 0;
    }
    Last edited by CommonTater; 09-24-2011 at 05:42 PM.
    Salem likes this.

  6. #21
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    AND another double header... Hi again Quzah!

  7. #22
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by CommonTater View Post
    AND another double header... Hi again Quzah!
    :eyebrow: No wonder your post count is so high!


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #23
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by quzah View Post
    :eyebrow: No wonder your post count is so high!
    Quzah.
    LOL... Point taken.

  9. #24
    Registered User Cess's Avatar
    Join Date
    Sep 2011
    Posts
    55
    ya I know I'm probably annoying I'm I am trying to learn and I really don't know what I am doing ok tried fixing it again...and I failed
    something wrong with the pause... dunno
    Code:
    #include <stdio.h>
    #include <math.h> 
    
    int main()
    {    
         int number;
         printf(" enter a positive number between 1 and 10:");
    
    scanf("%d",&number);
         
         if( (number < 1) || (number > 10) ) 
            printf("The number is out of range. (1-10)\n");
         
    system("PAUSE");
    return 0;
    }

  10. #25
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Cess View Post
    ya I know I'm probably annoying I'm I am trying to learn and I really don't know what I am doing ok tried fixing it again...and I failed
    something wrong with the pause... dunno
    Code:
    #include <stdio.h>
    #include <math.h> 
    
    int main()
    {    
         int number;
         printf(" enter a positive number between 1 and 10:");
    
    scanf("%d",&number);
         
         if( (number < 1) || (number > 10) ) 
            printf("The number is out of range. (1-10)\n");
         
    system("PAUSE");
    return 0;
    }
    When stuff like that happens... look up the keyword in your C library documentation... (which is exactly what I just did)

    In this case the problem is that you need to #include <stdlib.h> or it doesn't know what system() is.
    Cess and quzah like this.

  11. #26
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by CommonTater View Post
    When stuff like that happens... look up the keyword in your C library documentation... (which is exactly what I just did)

    In this case the problem is that you need to #include <stdlib.h> or it doesn't know what system() is.
    I did this exact thing when I wrote that calculator earlier.

    I know where a bunch of functions are from, but I don't have them all memorized. What's the point, when I can make a new tab, go up to my URL bar and type "man system(3)" and have it pull up the man page for me?


    Quzah.
    Hope is the first step on the road to disappointment.

  12. #27
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by quzah View Post
    I did this exact thing when I wrote that calculator earlier.

    I know where a bunch of functions are from, but I don't have them all memorized. What's the point, when I can make a new tab, go up to my URL bar and type "man system(3)" and have it pull up the man page for me?
    Quzah.
    With over a thousand functions in the library, nobody is going to memorize even half of them... and it only gets worse in Windows API where there are over 30,000 functions... Knowing how to look stuff up is probably the programmer's second most important skill.

    And ... ... in Pelles C all you have to do is press F1.

  13. #28
    Registered User Cess's Avatar
    Join Date
    Sep 2011
    Posts
    55
    ok I'm getting closer... I got 1 now I'm on number 2 and I need help again Lol thank you guys for being patient and helpful to a newbie like me!
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
     
    
    int main()
    {    
         int number;
         printf(" enter a positive number between 1 and 10:");
         scanf("%d",&number);
         
         if( (number < 1) || (number > 10) ) 
            printf("The number is out of range. (1-10)\n");
         
         /* Check to see if number is odd or even #1 */
         if ((number & 1) > 0)
          printf("%d is odd\n",number);
          else 
          printf("%d is even\n", number); 
         
          /* cube the number #2 */
          number*number*number
          printf("%d is the cube of that number\n"); 
          
        
    system("PAUSE");
    return 0;
    }

  14. #29
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You need to assign the value with =, which you aren't doing, and you don't even have it compilable at the moment:
    Code:
    //cube number
    number = number * number * number;

    Quzah.
    Hope is the first step on the road to disappointment.

  15. #30
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ok... so the number is out of range... what do you do about that?
    hint: you don't let it go crashing down into the rest of your program, causing even more problems.

    number*number*number does exactly nothing... the compiler should report it as a syntax error.

    Your last printf might read better as
    Code:
    printf("%d^3 = %d\n", number, number * number * number);
    Last edited by CommonTater; 09-24-2011 at 06:32 PM. Reason: added code tags

Page 2 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework class help
    By nofear_k11 in forum C Programming
    Replies: 2
    Last Post: 09-02-2011, 06:06 AM
  2. homework assistance wanted: using a class as a vector
    By DHart07 in forum C++ Programming
    Replies: 5
    Last Post: 11-02-2010, 03:12 PM
  3. homework help - overloaded constructor taking char or int
    By DHart07 in forum C++ Programming
    Replies: 7
    Last Post: 10-06-2010, 03:57 AM
  4. homework help wanted - Class member functions
    By DHart07 in forum C++ Programming
    Replies: 16
    Last Post: 09-29-2010, 01:43 AM
  5. Replies: 27
    Last Post: 10-11-2006, 05:27 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21