What im trying is to input 'yes' to continue and reset all values or 'no' to exit the program but i have tried to figure it out but im having trouble please help.thanks

#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main()
{
    float num1,result;
    char sym;
	

  printf("Calculator Is ON\n");
	
	do{
		
		
		result=0.0;
		printf("Result=%f\n", result);
		fflush(stdin);
		scanf("%c",&sym);
		

		while((sym!='r') && (sym!='R'))
	{
		
		scanf(" %f",&num1);
    
		switch(sym)
		{
			case'+':
			{
				result+=num1;
				printf("Result = %f\n",result);
				break;
			}
			case'-':
			{ 
				result-=num1;
				 printf("Result = %f\n",result);
				 break;
				 }
			case'*':
			{
				 result*=num1;
				 printf("Result = %f\n",result);
				 break;
			}
			case'/':
			{
				result/=num1;
				printf("Result = %f\n",result);
				break;
			}
			case'%':
			
				printf(" %c is an unknown operation\nReenter, your last line:",sym);
				break;
	
				
				
		}
		
		
		
		scanf(" %c",&sym);
	
	}
	    printf("Final result=%f",result);
         printf("\nAgain [y/n]\n");
			
	}
	
	while((result!='n') && (result!='N'));
	fflush(stdin);
    scanf(" %c",&sym);
	
	
	
	
    return 0 ;
}

These are questions for you to consider, not to tell me:

Where do you ask for YES or NO?
Where do you accept the answer? Into what variable?
Where is the end of the loop that requires the answer? What makes it continue/exit?

Do all these lines make sense in the order you wrote them?

Also, see this

ok now i took your advice and this is what i got but i still have several bugs that i cant seem to fix....

#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main()
{
    float num1,result;
    char sym, choice;
	

  printf("Calculator Is ON\n");
	
	do{
		
		
		result=0.0;
		printf("Result=%.1f\n", result);
		fflush(stdin);
		scanf(" %c",&sym);
		

		while((sym!='r') && (sym!='R'))
	{
		
		scanf(" %f",&num1);
    
		switch(sym)
		{
			case'+':
			{
				result+=num1;
				printf("Result = %.1f\n",result);
				break;
			}
			case'-':
			{ 
				result-=num1;
				 printf("Result = %.1f\n",result);
				 break;
				 }
			case'*':
			{
				 result*=num1;
				 printf("Result = %.1f\n",result);
				 break;
			}
			case'/':
			{
				result/=num1;
				printf("Result = %.1f\n",result);
				break;
			}
			case'%':
			
				printf(" %c is an unknown operation\nReenter, your last line:",sym);
				break;
	
				
				
		}
		
		
		
		scanf(" %c",&sym);
	
	}
	    printf("Final result=%.1f",result);
         printf("\nAgain [y/n]\n",choice);
		scanf(" %c",&choice);
		
	}	

	
	
		
	
	while((choice=='y') && (choice!='Y'));
	do{
		result=0.0;
		printf("Result=%.1f\n", result);
		fflush(stdin);
		scanf(" %c",&sym);
	}
		
	while((choice!='n') && (choice!='N'));

	{
	
	
				
		switch(sym)
		{
			case'+':
			{
				result+=num1;
				printf("Result = %.1f\n",result);
				break;
			}
	
			case'/':
			{
				result/=num1;
				printf("Result = %.1f\n",result);
				break;
			 		
				}
				scanf(" %c",&sym);
				
				
		}
	    printf("Final result=%.1f",result);
		printf("\nAgain [y/n]\n",choice);
		scanf(" %c",&choice);
	}




    
    return 0 ;
}

This statement on line 78 while((choice=='y') && (choice!='Y')); seems to do nothing -- unless choice is 'y' or 'Y' in which case you have an endless loop.

Please reformat your code. We can't tell where one loop ends and another starts. There are too many blank lines that simply hide the structure. And your indenting is too inconsistent to help in understanding.

Use the link to format so it's readable. And follow the other link I gave you too.

yeah thats what i figured out WaltP...
so instead this is what i got and it works

#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main()
{
    float num1,result;
    char sym, choice;
     printf("Calculator Is ON\n");
	
	do{
		
		
	result=0.0;
	printf("Result=%.1f\n", result);
        scanf(" %c",&sym);
	
        while((sym!='r') && (sym!='R'))
	{
	scanf(" %f",&num1);
    
        switch(sym)
	{
	case'+':
	{
	result+=num1;
	printf("Result = %.1f\n",result);
	break;
	}
	case'-':
	{ 
	result-=num1;
	printf("Result = %.1f\n",result);
        break;
				 }
	case'*':
	{
	result*=num1;
        printf("Result = %.1f\n",result);
	break;
	}
	case'/':
	{
	result/=num1;
	printf("Result = %.1f\n",result);
	break;
	}
	case'%':
	printf(" %c is an unknown operation\nReenter, your last line:",sym);
	break;
	}
	scanf(" %c",&sym);
	
	}
	    printf("Final result=%.1f",result);
         printf("\nAgain [y/n]\n",choice);
		scanf(" %c",&choice);
		
	}			
	while((choice!='n') && (choice!='N'));
        {
        }
        return 0 ;
        }

Formatting is still crap...

yeah i know thanks for your help im going to get on that formatting

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.