displayed in a right-hand column as an integer if the current letter is your first name’s initial
and as a character otherwise.thi is what I have so far.
#include
{
int alphaLft;
int runningTotal=0;
int aveRght;
int alphaNum=0;
/* The loop goes while alphaLft =< 122, and alphaLft increases by one every loop*/
for ( alphaLft = 97; alphaLft =< 122; alphaLft++;)
{
alphaNum= alphaNum++;
runningTotal= runningTotal + alphaNum;
aveRght= runningTotal / alphaNum;
}
printf( "%c, %c", alphaLft,aveRght );
}
mark willisPosted Sep 20, 2008, 7:38 PM
AlanPosted Sep 20, 2008, 6:53 PM
This is actually a C# rather than a C forum, Mark, but as it's a Saturday I'll finish it off for you anyway assuming I've understood the question correctly:
#include
#include
#include
int
main(){
char name[12];printf(
"Enter your first name : ");scanf(
"%s", name); char first = tolower(name[0]);printf(
"\nFirst letter is '%c'\n", first);printf(
"\nPress any key to display successive letters of alphabet and the average so far\n"); int alphaLft; int runningTotal=0; int aveRght; int alphaNum=0; /* The loop goes while alphaLft =< 122, and alphaLft increases by oneevery loop*/
for ( alphaLft = 97; alphaLft <= 122; alphaLft++){
getch();
runningTotal += alphaLft;
alphaNum++;
aveRght= runningTotal / alphaNum;
if (alphaLft == first)printf(
"\n%c, %d", alphaLft,aveRght ); elseprintf(
"\n%c, %c", alphaLft,aveRght );}
printf(
"\n\n");return
0;}