#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
main()
{
float a,b,sign;
cout%26lt;%26lt;"enter two numbers";
cin%26gt;%26gt;a%26gt;%26gt;b;
cout%26lt;%26lt;"choose a sign";
cin%26gt;%26gt;sign;
if (sign==1)
{sign=a*b;
cout%26lt;%26lt;sign;}
if (sign==2)
{sign=a+b;
cout%26lt;%26lt;sign;}
if (sign==3)
{sign=a/b;
cout%26lt;%26lt;sign;}
if (sign==4)
{sign=a-b;
cout%26lt;%26lt;sign;}
getch()
}
}
Sos, plz solve the errors c++(core)?
what kind of math is that??????????
ummmmmmm.................................
dont know sorry
Reply:#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
main()
{
float a,b,sign;
cout%26lt;%26lt;"enter two numbers";
cin%26gt;%26gt;a%26gt;%26gt;b;
cout%26lt;%26lt;"choose a sign";
cin%26gt;%26gt;sign;
if (sign==1)
{sign=a*b;
cout%26lt;%26lt;sign;}
if (sign==2)
{sign=a+b;
cout%26lt;%26lt;sign;}
if (sign==3)
{sign=a/b;
cout%26lt;%26lt;sign;}
if (sign==4)
{sign=a-b;
cout%26lt;%26lt;sign;}
cout%26lt;%26lt;flush;
getch();
}
// Note : you can remove cout%26lt;%26lt;flush; it forces the cout to write on the screen before the pause caused by getch();
Reply:Unless you can be more specific regarding an error (logical) ... as I do not understand the intent of the code other than the obvious ... there are two syntax errors :
(1) Missing semicolon after "getch()"
(2) An excess brace after the line mentioned above.
I would also clean up the code by using a simple switch statement and a few other minor adjustments, as follows :
#include %26lt;conio.h%26gt;
#include %26lt;iostream.h%26gt;
void main()
{
float a, b, result;
int operator;
cout %26lt;%26lt; "Enter two numbers :";
cin %26gt;%26gt; a;
cin %26gt;%26gt; b;
cout %26lt;%26lt; "Select an operator.";
cout %26lt;%26lt; "1. Multiplication";
cout %26lt;%26lt; "2. Addition";
cout %26lt;%26lt; "3. Division";
cout %26lt;%26lt; "4. Subtraction";
cin %26gt;%26gt; operator;
switch (operator)
{
case 1 :
result = (a * b);
break;
case 2 :
result = (a + b);
break;
case 3 :
result = (a / b);
break;
case 4 :
result = (a - b);
break;
}
cout %26lt;%26lt; "Result = " %26lt;%26lt; result;
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment