Maker Pro
Maker Pro

C Programming

CyberWizard

Sep 17, 2014
15
Joined
Sep 17, 2014
Messages
15
I though i could help my younger sister with some homework, boy was i wrong... :p

The code was supose to accept 2 integer and print the sum of all integers beetween them.

Ex: 5 - 7 = 5+6+7 = 18

Instead it just runs endsly :p


#include <stdio.h>
#include <locale.h>

int fSoma(int valor1, int valor2)
{
int aux; // Variavel auxiliar
int c; // Contador
c=0;
aux=0;
for(c=valor1;c=valor2;c++ )
{
aux=aux + c;
printf("\n A somar %i a %i",c,aux);
}
return(aux);
}
void main()
{
int a;
int b;
int result;

setlocale(LC_ALL,"Portuguese"); /* Activa o teclado português */
printf("\n Qual o numero mais baixo ?");
scanf("%i",&a);
printf("\n O numero %i foi selecionado",a);
printf("\n\n Qual o numero mais alto ?");
scanf("%i",&b);
printf("\n O numero %i foi selecionado",b);
result=fSoma(a,b);
printf("O somatório é:%i",result);



}

What wrong here? Can some1 help me out ?
 

JWHassler

Dec 22, 2014
86
Joined
Dec 22, 2014
Messages
86
I think the line that reads
for(c=valor1;c=valor2;c++ )
should actually read as
for(c=valor1;c>valor2;c++ )
.. this happens to me all the time.
Some compilers can warn you about assignments appearing where logical tests are called for.
 
Top