I'm writing a program using an array.
Write a program that asks for user input of two integers, write the code so that the program does the sum of two integers, the subtraction of two integers, the division of two integers, the multiplication of two integers and stores the results in an array and outputs the results of that array to the screen.
My program seems to work, but I'm wondering if I did the array part right. Also, when I enter -1 to end it makes me enter another number before it will close out the program. Not sure why this is.
Code:
#include <stdio.h>
int main ( void )
{
int x;
int y;
float array[4];
printf( "Enter two integers: \n" );
scanf( "%d" "%d",&x, &y );
while( x != -1 )
{
array[0] = x + y;
array[1] = x - y;
array[2] = x * y;
array[3] = x / ( float )y;
printf( "The results of the sum of the two integers is: %.2f\n", array[0] );
printf( "The results of the subtraction of the two integers is: %.2f\n", array[1] );
printf( "The results of the multiplication of two integers is: %.2f\n", array[2] );
printf( "The results of the division of two integers is: %.2f\n", array[3] );
printf( "Enter two integers: \n" );
scanf( "%d" "%d",&x, &y );
}
return 0;
}