Thread: Need help

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    21

    Need help

    Hello, need help please.
    Can't get it right, Not working a count of how much maximum number was typed. what's wrong ? Thank you.
    Code:
    #include <stdio.h>
    #define n 5
    int main()
    {        
        int i, num[n], max, qty = 1, ch;
        for (i = 0; i < n; i++)
        {
            printf("Please enter num %i\n", i);
            scanf("%i",&num[i]);
        }
        max = num[0];
        for (i = 0; i < n; i++)
        {        
            if (num[i] > max)
            {
                max = num[i];
            }
            if (num[i] == max)  // Need to calculate how many times the maximum number is.
            {
                qty++;
            }
        }
        printf("The highes number %i  was times %d \n", max, qty);  // need to print the max number and qty of maximum number.
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,596
    Every time you have a new max, you need to set qty to 1
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Tags for this Thread