plz help!

This is a discussion on plz help! within the C Programming forums, part of the General Programming Boards category; I'm having trouble with my school assignment. The program is suppose to ask to user to input some temperature values(which ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    5

    plz help!

    I'm having trouble with my school assignment. The program is suppose to ask to user to input some temperature values(which it does) then it is suppose to count the number of Hot Days (85 or <), Pleasant Days (65-84), and Cold Days (64 or >) wich it does also it also calculates the average of temperatures entered in by the user. What I can't figure out is how to print the values for Hot Days, Pleasant Days, and Cold Days. I would appreciate any help you can offer, hear is my code....

    Code:
    /*Program to process a collection of daily high temperatures
    Written by Janelle Shew
    Adapted from various course handouts and book
    February 2008
    Language written in C (gcc target)*/
    
    #include <stdio.h>
    
    #define sentinel 00
    
    int main(void)
    {
     int	 hot = 0,
    	 pleasant = 0,
    	 cold = 0,
    	 sum = 0,
    	 count,
    	 temp;
     double  average;
    
    sum=0;
    count=0;
    printf("Enter temperature (00 to quit): ", sentinel);
    scanf("%d", &temp);
    while (temp != sentinel) 
    {  if (temp <= 59)
       { ++cold; } 
       else if (temp >= 60 && temp<= 84)
        ++pleasant;
      else 
        ++hot;
       sum=sum+temp;
       count++;
       printf("Enter temperature (00 to quit): ", sentinel);
       scanf("%d", &temp);
    }
    printf("%d Hot Days:\n", hot);
    printf("%d Pleasant Days:\n", pleasant);
    printf("%d Cold Days:\n", cold);
    printf("%d", temp);
    printf("There are %d total temperatures\n", count);
    average=(double)sum/(double) count;
    printf("\nAverage temperature is %8.2f\n", average);
     
    return (0);
    }
    This is what the output looks like:

    Enter temperature (00 to quit):45
    Enter temperature (00 to quit):34
    Enter temperature (00 to quit):67
    Enter temperature (00 to quit):87
    Enter temperature (00 to quit):89
    Enter temperature (00 to quit):95
    Enter temperature (00 to quit):77
    Enter temperature (00 to quit):39
    Enter temperature (00 to quit):00
    3 Hot Days:
    2 Pleasant Days:
    3 Cold Days:
    There are 8 total temperatures

    Average temperature is 66.62

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    It looks like it's functioning correctly.

    printf("Enter temperature (00 to quit): ", sentinel); //sentinel is unneeded in this line. You don't actually print it here.

  3. #3
    Nub SWE
    Join Date
    Mar 2008
    Location
    Dallas, TX
    Posts
    133
    Search the forum. This exact question has been asked prior and solved.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    5
    The question that I'm looking for at this point hadn't been answered yet. Sorry if I was unclear. The program runs fine I however I just need the program to print the values of Hot days.

    Meaning when the values are inputed by the user and the results show that

    "2 Hot Days: "

    I need the values of the Hot Days to print along side the Hot Days count. So that a user who entered Hot Days of 90 and 86...results will show like this....

    "2 Hot Days: 90 86"

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    Perhaps you could store the tempuratures in a couple of linked lists, so that you can print the hot, fair, and cold days tempuratures out again after you calculate the average tempurature.

  6. #6
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    What happens if you enter 0 degrees and you don't want to quit?
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  7. #7
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    Maybe op doesn't live in a place where it gets that cold.

  8. #8
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,474
    Quote Originally Posted by citizen View Post
    Maybe op doesn't live in a place where it gets that cold.
    It is not so cold... if we are talking Fahrenheit and not Kelvin (I'm regular with Cilcius... so 0 is warm enough )
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  3. plz help here, noob actually .D
    By BjoRn3n in forum C++ Programming
    Replies: 1
    Last Post: 03-07-2005, 02:04 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21