Help with integer sum using for and while loops
I have an assignment that calls for a C program using a for loop AND a while loop that will receive an integer (called daNumba) and double it -- Using the integer the program will call the sumFor function and then the sumWhile function. These functions will both sum the values from daNumba to (daNumba * 2) ifdaNumba is positive. If daNumba is not positive it will add the values from (daNumba*2) to daNumba. Both functions will receive the value of daNumba and return a summed value. The only difference between the 2 functions is that sumFor will only use for loops and sumWhile will only use while loops. We are not to use arrays.
The program compiles without error. So far my while loop works for positive integers, but not with a negative integer (I have it commented out) I cannot get the for loop to work properly This is what I have so far -- I am stuck.... I am not looking for my work to be done, but to be pointed in a direction that will help me understand how to properly code my assignment.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main ()
{
/* Declare variables */
int daNumba, daNumba2, sumFor=0, sumWhile=0;
/* Display welcome message */
printf("\nWelcome to sumTimes2.\n");
/* Message indicating what the program will do */
printf("\nThis program will sum the integers between the one you enter and\n");
printf("the integer that is twice that value.\n");
/* Ask the user to enter and receive an integer */
printf("\nPlease enter your integer: ", daNumba);
scanf("%d", &daNumba);
/* sumWhile program */
sumWhile=daNumba;
daNumba2=daNumba*2;
while(daNumba<daNumba2)
{
sumWhile += daNumba;
++sumWhile;
++daNumba;
/*
else if(daNumba>daNumba2)
++sumWhile;
++daNumba2;
*/
}
/* sumFor program */
sumFor=daNumba;
for(daNumba=sumFor; sumFor==daNumba2; ++sumFor)
{
if(daNumba>0)
sumFor=daNumba;
else if(daNumba<0)
sumFor=daNumba;
sumFor += daNumba+sumFor;
daNumba++;
sumFor++;
}
/* Display test statistics */
printf("\nFor says the sum is %d\n", sumFor);
printf("While says the sum is %d\n", sumWhile);
/* Display ending thank you message */
printf("\nThank you for using sumTimes2. Bye!\n\n");
/* Return 0 for the compiler */
return 0;
}