![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
Matticus
You should try planning this out on paper first, perhaps with a flow chart, to determine how the logic should be structured.
You might want to consider using the value of 'i' to control the loop instead, and using an "if()" within the loop to validate the input.
Thanks, I was less confused when I made a flow chart.
This is what I came up with:
I'm pretty sure that the logic is right, but
printf("%d",input)==1 must not work, if that's the problem :/
What is wrong with my code?
Code:
#include <stdio.h>
int main(void)
{
int input;
int i;
int t;
int sum;
i = 1;
sum = 0;
printf("Enter an integer.");
scanf("%d",&input);
while(input>=i)
{
if(printf("%d",input)==1);
if(input>i)
{
t = (i*i)+1;
printf("%d ", t);
sum = sum + t;
}
else
{
printf("= %d",sum);
sum = 0;
i = 1;
}
}
printf("That is not an integer.");
return 0;
}