Thread: Need help with a credit card program

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    1

    Need help with a credit card program

    I'm trying to get my code to assign a credit card type of Bronze, Silver, Gold, or Platinum based on these conditions


    CCTYPE AGE_REQ SAL_REQ REF_REQ YEA_REQ
    Bronze Yes Yes No <2
    Silver Yes Yes No >=2
    Gold Yes Yes Yes <2
    Platinum Yes Yes Yes >=2


    How would i code it to make it check the conditions AGE_REQ, SAL_REQ, REF_REQ, YEA_REQ and assign a CC Type


    Here's my code for the rest of the program


    Code:
    #include <stdio.h>
    
    
    int main() {
    int AGE_REQ, SAL_REQ, REF_REQ, request_number = 1, runAgain = 1;
            float YEA_REQ;
    
    
            do{printf("************* Credit Card Program (Request# <%d>)\n", request_number);
            printf("Age greater or equal than 15 (1->Yes, 0->No) ?: ");
            scanf("%d", &AGE_REQ);
            printf("Salary greater or equal than 40K (1->Yes, 0->No) ?: ");
            scanf("%d", &SAL_REQ);
            printf("Any references (1->Yes, 0->No) ?: ");
            scanf("%d", &REF_REQ);
            printf("Enter years in current job: ");
            scanf("%f", &YEA_REQ);
    
    
            if (YEA_REQ < 0 || YEA_REQ > 90) {
                    do {printf("INVALID years value\n");
                    printf("Enter years in current job: ");
                    scanf("%f", &YEA_REQ);
                    } while(YEA_REQ < 0 || YEA_REQ > 90);
            }
    
    
    printf("************* Information provided *************\n");
    
    
            if (AGE_REQ == 1) {
                    printf("Age greater or equal to 15\n");
                    } else if (AGE_REQ == 0) {
                    printf("Age less than 15\n");
            }
    
    
    if (SAL_REQ == 1) {
                    printf("Salary greater or equal than 40k\n");
                    } else if (SAL_REQ == 0) {
                    printf("Salary less than 40k\n");
            }
    
    
    if (REF_REQ == 1) {
                    printf("References availible\n");
                    } else if (REF_REQ == 0) {
                    printf("No references\n");
            }
    
    
    printf("Years in current job: %.1f\n", YEA_REQ);
    
    
            printf("Do you want to run the classification Program again? (1->Yes, 0->No): ");
            scanf("%d", &runAgain);
            request_number ++;
            } while (runAgain == 1);
    
    
            printf("Thanks for using the Credit Card program\n");
    
    
            return 0;
    
    
    }

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Use logical AND to build a more complex test, and then check that the person meets all of the qualifiers.

    Code:
    {
        const char *assigned = NULL;
        if (refreq && salreq && agereq && yeareq >= 2.0f) assigned = "Platinum";
        else if (refreq && salreq && agereq && yeareq < 2.0f) assigned = "Gold";
        else if (salreq && agereq && yeareq >= 2.0f) assigned = "Silver";
        else if (salreq && agereq && yeareq < 2.0f) assigned = "Bronze";
        else assigned = "Rejected";
        printf("%s\n", assigned);
    }
    Last edited by whiteflags; 10-03-2016 at 09:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C: Credit Card Number Validator - Luhn Algorithm
    By Lioneyexp in forum C Programming
    Replies: 1
    Last Post: 02-07-2012, 07:06 PM
  2. [Help] Program : How to validate credit card number
    By kingofdcp in forum C Programming
    Replies: 13
    Last Post: 10-31-2009, 12:58 AM
  3. I need help with this last project! Credit Card Program!
    By ClearSights in forum C++ Programming
    Replies: 18
    Last Post: 10-27-2008, 10:08 AM
  4. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2003, 12:23 AM

Tags for this Thread