cant figure out where to put the loop....
Well I finally got my basic accoutning program done, but I want it so that it doesnt quit right after it computes the info (so people dont have to use command everytime....
I cant figure out where to put
Code:
while( (c=getchar()) != EOF && c != '\n' ){ }
no matter where i think is appropriate it still just ends the program once computing is done...
Code:
#include <stdio.h>
int PMR ( int input );
int ROA ( int input );
int WC ( int input );
int c;
float pmr;
float ni;
float ns;
float roa;
float avg;
float wc;
float ca;
float cl;
int main()
{
int input;
printf( "Welcome to the Accounting Calculator v.1\n" );
printf( "NOTE: DO NOT USE COMMAS! USE PERIOD TO PUT IN DECIMALS!\n" );
printf( "Select from one of the following options by entering the number it corresponds to\n");
printf( "\n");
printf("1. Profit Margin Ratio\n");
printf("2. Return on Assets\n");
printf("3. Working Capital\n" );
printf("4. Exit program\n");
printf("Selection: ");
scanf("%d", &input);
switch ( input ) {
case 1:
PMR( input );
break;
case 2:
ROA( input );
break;
case 3:
WC( input );
break;
case 4:
printf("Thanks you for using the accounting calculator\n");
break;
default:
printf("Bad input, quitting!\n");
break;
}
}
int PMR ( int input )
{
printf( "Enter the Net income\n" );
scanf("%f", &ni);
printf( "Now enter the Net sales\n" );
scanf("%f", &ns);
printf( "Your profit margin ratio is " );
pmr = ni/ ns;
pmr = pmr* 100;
printf("%.2f", pmr);
printf( "%%\n" );
printf( "That means you are making %.2f cents off each dollar\n");
printf( "press any button to exit the program\n" );
while( (c=getchar()) != EOF && c != '\n' ){ }
}
int ROA ( int input )
{
printf( "Enter the Net income\n" );
scanf("%f", &ni);
printf( "Now enter the average of total assets\n" );
scanf("%f", &avg);
printf( "Your Retun on assets is " );
roa = ni/ avg;
roa = roa* 100;
printf("%.2f", roa);
printf( "%%\n" );
}
int WC ( int input )
{
printf( "Enter the Current assets\n" );
scanf("%f", &ca);
printf( "Now enter the Current liabilities \n" );
scanf("%f", &cl);
printf( "Your Working capital is " );
wc = ca- cl;
printf("%3.f\n", wc);
printf( "press any button to exit the program\n" );
getchar ();
return 0;
while( (c=getchar()) != EOF && c != '\n' ){ }
}