i've been learning c for about, 2 days, and i tried to make a text-based calculator, and everything was going fine until i realized it is only doing addition... this is the code i made
Code:
#include <stdio.h>
int mult( int x, int y );
int add( int t, int u );
int sub( int z, int w );
int div( int a, int b );
int main()
{
int first;
int x;
int y;
int t;
int u;
int z;
int w;
int a;
int b;
int mult( int x, int y );
int add( int t, int u );
int sub( int z, int w );
int div( int a, int b );
printf( "press 1 for addition, 2 for subtraction, 3 for multipulcation, or 4 for division" );
scanf( "%d", &first );
if( first = 1 ) {
printf( "Please enter your first number: " );
scanf( "%d", &t );
printf ( "Now your second number please: " );
scanf ( "%d", &u );
printf ( "Your answer is: %d\n", add ( t, u ) );
getchar();
}
else {
if ( first = 2 ) {
printf ( "Please enter your first number: " );
scanf ( "%d", &z );
printf ( "Now your second number please: " );
scanf ( "%d", &w );
printf ( "Your answer is: %d\n", sub( z, w ) );
getchar();
}
else {
if ( first = 3 ) {
printf ( "Please enter your first number: " );
scanf ( "%d", &x );
printf ( "Now your second number please: " );
scanf ( "%d", &y );
printf ( "Your answer is: %d\n", mult( x, y ) );
getchar();
}
else {
if ( first = 4 ) {
printf ( "Please enter your first number: " );
scanf ( "%d", &a );
printf ( "Now your second number please: " );
scanf ( "%d", &b );
printf ( "Your answer is: %d\n", div( a, b ) );
getchar();
}
}
}
}
}
int add (int t, int u)
{
return t + u;
}
int sub (int z, int w)
{
return z - w;
}
int mult (int x, int y)
{
return x * y;
}
int div (int a, int b)
{
return a / b;
}
i've gotten rid of any errors, but when i try it only does addition no matter what i choose, i think it may have something to do with it not recognizing what i put in for "first", any help would be nice
p.s i know i suck, but i've only got 1 or 2 days under my belt