Hi there ..
Can someone help me with this Assignment .. I dunno what's the problem in it ><"
There are no Errors.. But in every operation I use The output look like :
Code:
1
You Choose Addition
Enter two numbers to add : 3 5
The sum = 3
Thank You..
Code:
2
You Choose Subtraction
Enter two numbers to subtract : 5 7
The difference = 5
Thank You..
In every option It seems like it took only the first number I enter ..
Also I have Proplems in the Division Part .. :S
Anyway .. This is the code I've written :
First These are the operations :
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Reminder
6.Minimum
7.Maximum
8.Exit
Using if_else_if .
And this is the Code :
Code:
#include <iostream>
#include <conio>
int main ()
{
int x , y , opt , answer ;
cout<< "*********************************"
<< "\n* Welcome to my Calculator ^^ *"
<< "\n* Choose What you want to do: *"
<< "\n* 1.Addition *"
<< "\n* 2.Subtraction *"
<< "\n* 3.Multiplication *"
<< "\n* 4.Division *"
<< "\n* 5.Reminder *"
<< "\n* 6.Minimum *"
<< "\n* 7.Maximum *"
<< "\n* 8.Exit *"
<< "\n*********************************" << endl;
cin>> opt;
if ( opt==1)
{
cout<< "You Choose Addition " << endl;
cout<< "Enter two numbers to add : " ;
cin>> x , y ;
answer = x + y ;
cout<< "The sum = " << answer << endl;
}
else if ( opt==2 )
{
cout<< "You Choose Subtraction " << endl;
cout<< "Enter two numbers to subtract : " ;
cin>> x , y ;
answer = x - y ;
cout<< "The difference = " << answer << endl;
}
else if ( opt==3 )
{
cout<< "You Choose Multiplication " << endl;
cout<< "Enter two numbers to multiply: " ;
cin>> x , y ;
answer = x * y ;
cout<< "The product = " << answer << endl;
}
else if ( opt==4 )
{
cout<< "You Choose Division " << endl;
cout<< "Enter two numbers to divide : " ;
cin>> x , y ;
if ( y!=0 )
{
answer = x/y ;
cout<< "The quotient = " << answer << endl;
}
else
{
cout<< "No Division over 0 ";
}
}
else if ( opt==5)
{
cout<< "You Choose Reminder " << endl;
cout<< "Enter two numbers to get reminder : " ;
cin>> x , y ;
answer = x % y ;
cout<< "The Reminder = " << answer << endl;
}
else if ( opt==6 )
{
cout<< "You Choose Minimum" << endl;
cout<< "Enter two numbers to find the minimum : ";
cin>> x , y ;
if (x>y)
cout<< "The minimum = " << x << endl ;
else
cout<< "The minimum = " << y << endl;
}
else if ( opt==7 )
{
cout<< "You Choose Maximum " << endl;
cout<< "Enter two numbers to find the maximum : ";
cin>> x , y ;
if ( x > y )
cout<< "The maximum = " << x << endl;
else
cout<< "The maximum = " << y << endl;
}
else if ( opt==8 )
cout<< "You Choose Exit" << endl;
else
{
cout<< "Error : Not Valid Option" << endl;
}
cout<< "\nThank You.." << endl ;
getch ();
return 0 ;
}
Actully .. I'm in my first grade in Computer Science .. ^^"
I'm also confused about if I can write if inside else if in Block ..
Any help greatly appreciated..