Posted on 2007-10-11
Last Modified: 2010-04-15
need a program taht does these
thanks guys

have 3 user defined routines: sqrnum, readnum, prompt
Ï prompt: will print the prompt Enter a number
Ï readnum: will input a decimal integer from the user
Ï sqrnum: will square the number and print the square of the number as a result
Ï the main function will contain a for loop to:
Ë request input by calling prompt
Ë obtain input by calling readnum
Ë if the number is not zero, it will print the result by calling sqrnum
Ë the program will terminate when zero is entered
Run the program and input 3 different numbers. Then enter zero to exit the program.
Question by:tsburt
    LVL 1

    Author Comment

    i don't know how to start this one...........any main points here?
    LVL 24

    Accepted Solution

    Just somethign to get you go

    void prompt(void) {
       printf("Enter a number: ");

    for readnum you probably like to use
    scanf or fgets + sscanf
    It seems it should have a return value of float so the prototype is:
    float readnum(void) {
         float result;
         /* make good use of fgets + sscanf or scanf */

    the prototyp of sqrnum will be
    float sqrnum(float sqrnum)
        /* implement the function */

    main is always

    int main(void) {
        float some_value;
        float some_value_squared;
        /* the loop  will be something like */

        do {
            some_value = read_num;
            if (is_valid(some_value)) { /* is_valid has to be provided by you e.g test on 0.0 or the like */
                some_value_squared = ...
       while (is_valid(some_value));

     return 0;

    This should give you a good start ....


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now