C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Counter Help Posted by madjm on 17 Nov 2012 at 10:02 AM
Hey guys i love the community you guys have here !

On to the problem i have a simple little program here it repeats using a do while loop i have a counter in the loop that should be counting and displays that value when the program is stoped.
For some reason the counter is not working what am i doing wrong here is the code.
 #include <stdio.h>
#include <conio.h>
#include  <stdlib.h>
int main()
{
    
    int num1,cnt;
    char repeat;
    cnt = 0 ;
    
    do {
    printf("\nEnter a number");
    scanf("%d",&num1);
    
    
    printf("\nEnter a next number [y] yes or no [no]");
    scanf("%s",&repeat);
    cnt = cnt + 1; // Here is counter //
    }
    
    while ( repeat != 'n');
    
    system("cls");
    printf("You ran the program %d",cnt);
    printf("times");
    
getch();

}
 

Thread Tree
madjm Counter Help on 17 Nov 2012 at 10:02 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.