• C


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.
Who is Participating?
fridomConnect With a Mentor CEO/ProgrammerCommented:
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 ....

tsburtAuthor Commented:
i don't know how to start this one...........any main points here?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.