Home Forums C Programming while statement again! Re: Re: while statement again!

#3491
GWILouisaxwzkla
Participant

could do:


/****************************************************************
* File Name : c:programstempCG.cpp
* Date : December,7,2008
* Comments : new project
* Compiler/Assembler :
* Modifications :
*
*
*
*
*
* Program Shell Generated At: 2:59:36 p.m.
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/


#include
//#include
//#include
//#include
//#include
//#include

//using namespace std;

//main function ******************************

int main ( )
{

char choice;
int number1 , number2 , number3 , number4,number5;
int average;
do
{
printf ( "enter a number: " );
scanf ( "%i" , & number1 );
printf ( "enter a number: " );
scanf ( "%i" , & number2 );
printf ( "enter a number: " );
scanf ( "%i" , & number3 );
printf ( "enter a number: " );
scanf ( "%i" , & number4 );
printf ( "enter a number: " );
scanf ( "%i" , & number5 );
printf ( "nthe average of the numbers is: " );
average = ( number1 + number2 + number3 + number4 + number5 ) / 5;
getchar (); //get new line characters
printf ( "%i" , average );
printf ( " nDo you want to calculate another average ? ( y or n ) " );
scanf ( "%c" , & choice );
getchar(); //get newline
while ( choice != 'y' && choice != 'n' )
{
printf ( "wrong input ( enter y or n ) " );
printf ( " nDo you want to calculate another average ? ( y or n ) " );
scanf ( "%c" , & choice );
getchar (); //get newline
}
}while ( choice != 'n' );


return 0 ;
}