Thread: Beginner C problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2021
    Posts
    1

    Beginner C problem

    Code:
    int main() {
        double firstInputCheck = 0;
        double MoneyEachMonth;
        char firstInputNewLine = '?';
        
        while (true) {
            if (firstInputCheck == 0 || firstInputNewLine != '\n' ) {
                printf("Enter how much money you will be putting towards loans/retirement each month: ");
                firstInputCheck = scanf(" %lf", &MoneyEachMonth);
                scanf("%c", &firstInputNewLine);
            } else {
                break;
            }
        }
    }
    When I try to put in an incorrect input (like bob) it proceeds to print the printf statement 3 times instead of just once.
    Attached Images Attached Images Beginner C problem-c-question-jpg 

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner's Problem
    By Gigabitten in forum C Programming
    Replies: 8
    Last Post: 11-27-2011, 05:56 PM
  2. Beginner's problem with C
    By scheng924 in forum C Programming
    Replies: 1
    Last Post: 05-19-2009, 03:44 PM
  3. Beginner problem
    By strokebow in forum C++ Programming
    Replies: 9
    Last Post: 09-13-2008, 09:54 AM
  4. Beginner's problem.. please help
    By jstevanus in forum C++ Programming
    Replies: 10
    Last Post: 12-08-2004, 04:08 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM

Tags for this Thread