473,378 Members | 1,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

What is wrong with this program, loop endless and "evens", "odds" output dummy values

1
Why is the below program is not coming out of the for loop and the variables outputting dummy values

Expand|Select|Wrap|Line Numbers
  1. /* oddeven.c: Illustrates looping construts */
  2. #include <stdio.h>
  3.  
  4. int main() {
  5.     for (; ;) {
  6.         int num;
  7.         int evens=0;
  8.         int odds=0;
  9.         puts("Enter integer: ");
  10.         scanf("%d", &num);
  11.         switch(num % 2){
  12.         case 0:
  13.              evens = evens + 1;
  14.              break;
  15.         case 1:
  16.            odds = odds + 1;
  17.            break;
  18.         }
  19.         printf("evens: %d Odds: %d\n", &evens, &odds);
  20.         if (evens + odds == 10)
  21.             break;
  22.  
  23.     }
  24.     return 0;
  25. }
Apr 13 '10 #1
2 1361
whodgson
542 512MB
Because the for loop does not have an end condition and int num has not been initialized.
Apr 13 '10 #2
newb16
687 512MB
because you reset cound for evens and odds every iteration - they never reach 10. And also you have prinf done wrong ( &odds, not odds ).
Apr 13 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Wildemar Wildenburger | last post by:
Hi there :) I don't know how else to call what I'm currently implementing: An object that behaves like a list but doesn't store it's own items but rather pulls them from a larger list (if they...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.