Page 1 of 212> Show 40 post(s) from this thread on one page

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   how can i solve this problem ??? (http://www.go4expert.com/forums/i-solve-t18530/)

 cooop 14Jul2009 01:46

how can i solve this problem ???

Write a program to simulate hand-held electronic calculator. Your program should execute as follows:
• Step 1: display a prompt and wait for the user to enter an instruction code (a single character):
‘-‘ for subtraction
‘*’ for multiplication
‘/’ for division
‘p’ for power
‘c’ to clear the current accumulator
‘s’ for square root
‘l’ for log
‘n’ for ln
‘q’ for quit
• Step 2: (if needed) display a prompt and wait for the user to enter a type float number (which we will call left-operand)
• Step 3: (if needed) display a prompt and wait for the user to enter a type float number (which we will call right-operand)
• Step 4: display the accumulated result at any point during processing and repeat steps 1 through 3 using a GOTO statement (no loops in this assignment).

Use a separate function enter_code to prompt the user for instruction code and to ensure that a valid code is entered. Also, use a separate function enter_operand for the entry of the left-operand and the right-operand. Finally, use another function compute to perform the indicated operation. (unless q was entered).

 fob500 14Jul2009 13:45

Re: how can i solve this problem ???

Ok this wont be that difficult.In the main you got to take the input from the user(what he wants to do) and than use switch(choice) or else you can use nested if else statements.Depending on the choice the user makes each choice would invoke the required function from main.For example
----------------------------------------------------------
int i;
switc(i)
{
case 1: assuming case 1 is addition
.
.
}
----------------------------------------------------------
I suggest you write something and post it coz no one's going to code for you.Let me know if it helped

 cooop 14Jul2009 13:59

Re: how can i solve this problem ???

Thnx.
If I want to use nsted if can u give me an example from one of them ?

 cooop 14Jul2009 14:07

Re: how can i solve this problem ???

Thnx.
If I want to use nsted if can u give me an example from one of them ?

 fob500 14Jul2009 14:20

Re: how can i solve this problem ???

main()
{

int choice;
printf("enter 1 for addition,2 for subtraction............")
if(choice==1)
{
..
.
}
else
if(choice ==2)
{
int diff = sub(x,y);
.
.
}
else
if
{
.
}
-----------------------------------------------------------------
and so on.You can also google "syntax of if-else" for more help.Hope that was helpful

 cooop 14Jul2009 14:21

Re: how can i solve this problem ???

Thnx :)

 cooop 16Jul2009 00:29

Re: how can i solve this problem ???

is this right ?
if it is wrong can u correct it so i can do the complite it :D

Code:

``` #include <iostream> #include <cmath> using namespace std; int main () {     float k,sum,x,y,p;     cout << " enter 2 values" ;     cin >> x,y;     if ( k == 1 )     {     sum = x+y;     cout << " addition is : " << sum << endl; } else if ( k == 2 ) { float division =( x/y && y!=0) || (y/x && x!=0); cout << " divisionis " << division << endl; } else if ( k == 3 ) { float subtraction = x-y || y-x ; cout << "subtraction" << subtraction << endl; } else if ( k == 4 ) { float multiplication = x*y; cout << "multiplication" << multiplication << endl ; } else if ( k == p ) { float power = pow(x,y) || pow (y,x); cout << "power" << power << endl; }```

 xpi0t0s 16Jul2009 02:51

Re: how can i solve this problem ???

> is this right ?

Well, does it work as you want? If not then it's not right. If it does then it is right.
Have you tried compiling it?
Did you get any errors?

Programming is very much about doing stuff yourself. If you're so stuck that you can't even plug code into a compiler then I would suggest you're way out of your depth already and should consider getting some extra tuition outside class otherwise you're never going to make it.

 hotnspicy 16Jul2009 06:41

Re: how can i solve this problem ???

in VB i can make it

 cooop 17Jul2009 03:44

Re: how can i solve this problem ???

Code:

```#include <iostream> #include <cmath> #include <stdio> using namespace std; int main ()     {       float first_num, second_num;       int which_one;                float result;        float dfirst; float  dsecond; float  dnum1; float  dnum2;                cout << "Please enter the first number : ";       cin >> first_num;       cout << "Please enter the second number : ";       cin >> second_num;       cout << "Press 1 to add the two numbers"           << endl           << "Press 2 to subtract the two numbers."           << endl           << "Press 3 to multiply the two numbers."           << endl           << "Press 4 to divide the two numbers."           << endl           << "Press 5 to sqrt numbers."           << endl           << "Press 6 to power the two numbers."           << endl             << "Press 7 to log the two numbers."           << endl;                                     cin >> which_one;       if (which_one == 1)         result = first_num + second_num;       if (which_one == 2)         result = first_num - second_num;       if (which_one == 3)         result = first_num * second_num;       if (which_one == 4)         result = first_num / second_num;       if (which_one ==5)       result = sqrt(first_num);       if (which_one == 6)         result = pow(first_num , second_num);         if (which_one == 7)         result = log(first_num );                       cout << "The result is " << result << endl;     int f; cin >> f; return 0; }```

what is goto statement ?
and how can i write c,q,ln ?

 All times are GMT +5.5. The time now is 03:41. Page 1 of 212> Show 40 post(s) from this thread on one page