Thread: Having problems with beginners code

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    32

    Having problems with beginners code

    Hello, first post here. I'm just starting out on my programming adventure. Pretty much I take random coding problems off the internet and try to solve them. I'm stumped on what to do with three of these though (mainly the first one). I know this is probably really simple code but any help would be greatly appreciated!

    1. Create the code to display each variable exactly as shown using the place holder code.

    given code:
    int a = 2323;
    float b = 76225.3235743876;
    String c = "Lupoli is a programmer";
    output to match:
    :2323: // nothing added
    :76225.323574: // nothing added
    :Lupoli is a programmer: // nothing added
    : 2323:
    :+76225.323574:



    So far for this one, I was trying to go one line at a time and have
    Code:
    #include <stdio.h>
    
    
    int main()
    {
            int a = 2323;
            float b = 76225.3235743876;
            String c = "Lupoli is a programmer";
    
    
            printf(": %i:",a);
    
    
            return 0;
    }
    When I try to compile it, it keeps giving me an undeclared error though.



    2. Ask the USER to enter any hour and minute, (2 separate variables) in military time of the day, determine the length of time left in the day in minutes. Do not use "if-else".

    3. Write a program that prompts the user for a radius and then prints:
    a. The area and circumference of the circle with that radius
    b. The volume and surface area of the sphere with that radius

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by blindchicken11 View Post
    When I try to compile it, it keeps giving me an undeclared error though.
    I'm going to guess that the undeclared thing is "String", since that is not a pre-defined data type in C. Maybe you want:

    Code:
    char c[] = "Lupoli is a programmer";
    "c" is a C string, but C strings are actually char arrays.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by blindchicken11 View Post
    Pretty much I take random coding problems off the internet and try to solve them.
    If you found the declaration you posted above there as well, it demonstrates that it might not be the best source for learning actually. I mean it might be valid in some language but not C.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    32
    Thanks MK, that seemed to do the trick.

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    Volume of shpere

    Hello, also my first post here..
    I feel a bit ashamed to ask it here, but I can't find answers elsewhere..

    So sorry for asking such an easy thing, as it may be for the most of you..
    But I am really pretty new to all of this, but motivated and enthusiastic about getting along.

    I was trying to write a program to calculate the Volume of a sphere.
    What I do not understand is, why my results when executed appear to be approximate results instead of exactly calculated.

    Code:
    #include <stdio.h>
    
    int main()
    {
        float v, r, pi;
        pi=3,14;
        printf("Type in the sphere's radius: ");
        scanf("%f", &r);
        
        v = (4.0 * pi * r * r * r / 3.0);
        printf("The volume of a sphere is %.2f\n", v);
        return 0;
    }

  6. #6
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Ahem ... "3.14" ... ahem

    Damm this cold!

    EDIT: And please don't hijack other people's posts.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with code
    By stdq in forum C Programming
    Replies: 7
    Last Post: 08-22-2011, 08:29 PM
  2. Need help with Code! Having problems.
    By Invertalon in forum C Programming
    Replies: 4
    Last Post: 03-05-2008, 06:17 AM
  3. Problems with code
    By skooter211 in forum C++ Programming
    Replies: 11
    Last Post: 06-23-2005, 06:30 PM
  4. Problems with code from the FAQ
    By Bhaunted in forum C++ Programming
    Replies: 1
    Last Post: 08-31-2004, 02:36 PM
  5. Problems with code
    By dasher in forum C++ Programming
    Replies: 6
    Last Post: 01-23-2002, 12:00 PM