I have made some changes. I have to use gets() for the first and last name. It is part of the assignment. I fixed the {}, I didn't realize I left them out because everything compiled okay. I have the array working and the sum and average work now. I am trying to print out part of the persons name. It is the last part of my code. Can someone look at it and tell me what I am doing wrong.
Code:
/*included files */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main()
{
/*variable declaration*/
unsigned int counter, count;
char fname[50], lname[50];
char CAPfirst[1], CAPlast[50], CAPfirstFull[50];
int favnum, i, j;
char theNums[8] [8];
int nums[8] = {0},sum = 0;
int lengthF, lengthL;
float numberCount = 0, average = 0;
/* Get first name from user*/
printf("Please enter your first name: ");
gets(fname);
/*get last name from user*/
printf("\nPlease enter your last name: ");
gets(lname);
/*get users favorite number*/
printf("\nPlease enter your favorite number:");
scanf("%d", &favnum);
/*take up to 8 numbers*/
printf("\nPlease enter up to 8 numbers to stop entering numbers enter zero\n");
printf("\n");
for (i=0;i<8;i++)
{
fgets(theNums[i], 8, stdin);
if (theNums[i][0]=='0') /*exit if zero*/
break;
else
nums[i]=atoi(theNums[i]);
numberCount ++; /*count numbers being entered*/
}
printf("\n\n");
/*calculate sum and average*/
for(j=0; j<i; j++){
sum +=nums[j];
average=(sum/numberCount);
}
/*count the number of characters in the first and last name*/
lengthF = strlen(fname);
lengthL = strlen(lname);
/*Capitalize first name*/
for(counter=0; counter<1; counter++)
CAPfirstFull[counter] = toupper(fname[counter]);
CAPfirstFull[counter] = '\0';
/*capitalize first initial of first name*/
for(counter=0; counter<1; counter++)
CAPfirst[counter] = toupper(fname[counter]);
CAPfirst[counter] = '\0';
/*capitalize last name*/
for(counter=0; counter<strlen(lname); counter++)
CAPlast[counter] = toupper(lname[counter]);
CAPlast[counter] = '\0';
/*print first and last name and favorite number*/
printf("\n%s %s your favorite number is %d", fname, lname, favnum);
/*print out how many numbers were entered*/
printf("\nYou entered %.0f numbers.\n", numberCount);
/*print out numbers entered*/
printf("\nHere are the numbers you entered\n");
for(i=0;i<numberCount;i++){
printf("%d",nums[i]);
printf("\n");
}
/*print sum and average*/
printf("\nThe total of the %.0f numbers you entered is %d", numberCount, sum);
printf("\nThe average of the %.0f numbers you entered is %.2f:", numberCount, average);
/*Did the user repeat any numbers*/
for(i = 0; i<8; i++)
{
for(j = 0; j<8; j++)
{
if (theNums[i] == theNums[j])
count++;
}
if(count == 1)
printf("There are duplicates");
}
/*is their favorite number part of the array*/
/*print first initial and last name in caps*/
printf("\nHere is your first initial and last name in all caps:\t %s %s", CAPfirst, CAPlast);
/*print out which name is larger*/
if (lengthF < lengthL)
printf("\nYour last name is larger then your first name\n");
else
printf("\nYour first name is larger then your last name\n");
/*print out nuumber of characters equal to smaller lengthF or lengthL*/
if (lengthF < lengthL)
for(counter=0; counter < lengthF; counter++)
printf("%s", CAPfirstFull);
else
for(counter=0; counter < lengthL; counter++)
puts(CAPlast);
getchar(); /*wait for keystroke to enter*/
return 0;
}