Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8301401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:56:06+00:00 2026-06-08T16:56:06+00:00

I continue to learn programming in C, and today I met a problem. In

  • 0

I continue to learn programming in C, and today I met a problem.
In my program, a user must enter a value of time in minutes, and my program will calculate it seconds(very simple, actually). But I want to set a rule, that time cannot be negative. So I used this code:

    if(a<=0)
    {
        printf("Time cannot be equal to, or smaller than zero, so the program will now terminate\n");
        exit(EXIT_FAILURE);
    }

but now, I don`t want to terminate my program, I want it to return to the state when a user has to enter a value.

I had a problem with terminating my program, but some search helped me, however I did not get any result searching how to restart my program.

This is the text of my program(I am working on Linux):

#include<stdio.h>
#include<stdlib.h>
main()
{
    float a;
    printf("\E[36m");
    printf("This program will convert minutes to seconds");
    getchar();
    printf("Now enter your time in minutes(e.g. 5):");
    scanf("%f", &a);
    printf("As soon as you will press the Enter button you`ll get your time in seconds\n");
    getchar();
    getchar();


    if(a<=0)
    {
        printf("Time cannot be equal to, or smaller than zero, so the program will now terminate\n");
        printf("\E[0m");
        exit(EXIT_FAILURE);
    }
    else
    {
        float b;
        b=a*60;
        printf("\E[36m");
        printf("The result is %f seconds\n", b);
        printf("Press Enter to finish\n");
        getchar();
    }
    printf("\E[0m");
}

P.S. I don`t know how to correctly name this function, so I call it restart, maybe it has a different name?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:56:08+00:00Added an answer on June 8, 2026 at 4:56 pm

    Both the solutions that have been posted work, but I personally like this approach better:

    // ...
    printf("Now enter your time in minutes(e.g. 5):");
    scanf("%f", &a);
    
    while(a <= 0){
       printf("Time cannot be equal to, or smaller than zero, please enter again: ");
       scanf("%f", &a);
    }
    

    I think it is more clear, and it gives the opportunity to have an error message and a regular message independent of each other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We were surprised to learn today that threads waiting on a ManualResetEvent continue waiting
I've written a Binary Tree program that asks the user questions to learn about
I want to continue one task because my head has some problem with a
Possible Duplicate: Does the compiler continue evaluating an expression where all must be true
Started to learn programming 2 months ago, in one of my little projects i
I have learn AS3 for sometime and I really want to continue develop it
I'm trying to learn Java, and came across a problem on one of the
I'm super new to programming and I've been using appengine to help me learn
I am wondering if I should continue to learn OCaml or switch to F#
I am just studying other user's PHP code right now to understand and learn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.