Total members 9950 | Gratitudes |It is currently Sat Feb 11, 2012 2:31 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: C++ While loop
PostPosted: Thu Nov 13, 2008 1:55 pm 
Offline
Beginner
User avatar

Joined: Sun May 25, 2008 5:34 pm
Posts: 95
Has thanked: 2 time
Have thanks: 1 time

Code:
#include <stdio.h>
main()
{
        int cnt = 0,            /* Count of numbers read. */
            tot = 0;            /* Total of numbers read. */

        /* Read until a read fails. */
        int num;
        while(scanf("%d", &num) == 1) {
                tot = tot + num;
                cnt = cnt + 1;
        }

        /* Print the average. */
        if(cnt)
                printf("Average is %g\n", (double)tot / (double)cnt);
        else
                printf("No numbers.\n");
}


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Why will my loop does not work  C-C++  atoivan  0
 do while loop and for loop C++ example help.  C-C++  sakorian  2
 Need help with code for a while loop program  Java  cathyd0890  4
 java loop at end of code ... soooo close i hope  Java  seaplus  0
 While loop  C-C++  mestz6  5

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 2 guests



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team