Quantcast
Viewing all articles
Browse latest Browse all 2703

Counter Help

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();

}
 


Viewing all articles
Browse latest Browse all 2703

Trending Articles