C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 5th, 2005, 03:21 PM
Just Jen Just Jen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 3 Just Jen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 52 sec
Reputation Power: 0
Unhappy Right Direction Please

I am taking a class in C++ Programing and our teacher is not explaining anything so the class will understand.
Our homework is to write a program for a simple calculator. Shouldn't be that big of a deal however he has not
explained what the codes mean or how to go about using them. We should understand from the book but to me it
is greek. Can anyone send me to a link or explain to me what the meanings are? I want to figure this out on my own
but without knowing what the codes mean there is no way I can do it.

Reply With Quote
  #2  
Old March 6th, 2005, 08:36 AM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
There's a post in the same page as yours with a calculator code written. I'm not suggesting stealing the code. Just, read it to understand how it works (as for the functions, just grab the book..functions are functions and shouldn't have any problem with them).

Reply With Quote
  #3  
Old March 6th, 2005, 09:31 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 273 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 35 m 2 sec
Reputation Power: 4
Refer to Yashwant Kanitkar. The book explains all concepts with vividity.

Reply With Quote
  #4  
Old March 6th, 2005, 05:10 PM
Just Jen Just Jen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 3 Just Jen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 52 sec
Reputation Power: 0
Ok

ok i got it to run however when i do the invert it will not do it and then when i start the * 100 like it is supposed to it just keeps on going an going... this is what i got so far..

#include<iostream>
#include <math.h>
using namespace std;

int main()
{
char Operator = ' ';
float Num1 = 0, Num2 = 0;


cout << "\t\t\t Calculator Functions : \n\n";
cout << " \t\t + (add) , * (mult) , ^ (expo) , \n ";
cout << " \t\t (I)nvert , (S)et value , (Q)uit, \n ";
cout << " \t\t show this (M)enu again. \n ";

do {

cin >> Operator;
Operator = toupper (Operator);
switch (Operator)
{
case 'S':
cin >> Num1;
break;

case '+':
cin >> Num2;
Num1 = Num1 + Num2;
break;

case '^':
cin >> Num2;
Num1 = pow (Num1, Num2);
break;

case '-':
cin >> Num2;
Num1 = Num1 - Num2;
break;

case '*':
cin >> Num2;
Num1 = Num1 * Num2;
break;

case 'I':
cin >> Num2;
Num1 = Num1 / Num2;
break;

case 'Q':
cout << " You have chosen to exit.\n";
break;

case 'M':
system ("cls");
cout << "\t\t\t Calculator Functions : \n\n";
cout << " \t\t + (add) , * (mult) , ^ (expo) , \n ";
cout << " \t\t (I)nvert , (S)et value , (Q)uit, \n ";
cout << " \t\t show this (M)enu again. \n ";


break;
}

if (Operator != 'Q')
cout << "\n\t\t\t\t" << Num1 << endl ;

}while (Operator != 'Q');

return 0;


}



Reply With Quote
  #5  
Old March 6th, 2005, 09:11 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 273 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 35 m 2 sec
Reputation Power: 4
What do you mean by "Invert" Operation? Do you want to inverse a number?
The "*100" example is not clear.Please elaborate.

Reply With Quote
  #6  
Old March 6th, 2005, 09:15 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 273 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 35 m 2 sec
Reputation Power: 4
From what I can infer from your example of "*100" , is that you must be getting "0".
Am I right?

Reply With Quote
  #7  
Old March 7th, 2005, 06:00 AM
Just Jen Just Jen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 3 Just Jen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 52 sec
Reputation Power: 0
I get an amount 3 times and then 0 until I stop the loop.

Reply With Quote
  #8  
Old March 7th, 2005, 11:57 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 273 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 35 m 2 sec
Reputation Power: 4
i
Quote:
Originally Posted by Just Jen
I get an amount 3 times and then 0 until I stop the loop.


You mean if you 3*100 , you get 300 and 0 ?

Reply With Quote
  #9  
Old March 7th, 2005, 12:10 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 273 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 35 m 2 sec
Reputation Power: 4
Where are you supplying value to variable Num1?
It is initialized to zero => result will be zero for "*" operator, irrespective of Num2's value.

What keyboard button sequence are you using? Meaning: After 1st loop, when your prog. prompts for second key press for operation,which button do you press?

I may not be able to help you unless you are specific.
(From my analysis of your prog, I disagree with you for printing an amount 3 times the orifginal value supplied)

Reply With Quote
  #10  
Old March 7th, 2005, 05:33 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Unhappy

Hey!

In the name of God...what the hell are you talking about? I've read all the posts and not one did I understand. What is that thing about 3 * 100 returns 0 ? Honestly, I don't follow the idea. Please, define each operation and what it does so you can make a function for each one...

The concept is simple:

Code:
 
1) Enter a number. 
2) Enter an operand
  2.1) If the operand if final (= or enter for example), go to(3).
  2.2) If not, prompt for a second number.
3) Show result.


The program should be a simple loop with an algorithm like the one above. When an operand is entered, you make a select case (for example). If the operand requires another number, prompt for it. If not, call the function with that only number and show the result.

Since you're working with C++....you, and that's only my opinion, could create a class called Calculator. you would give it all the methods (operations) and a couple of variables (parameters for those operations) and simply invoque for example:

- Calculator.Add(N1, N2)
- Calculator.Substract(N1, N2)
- Calculator.Multiply(N1, Ntimes)
- Calculator.ToPower(N1, Nexp)
- Calculator.Exponential(N) //there's an example of a single number operand e**x
- Calculator.ShowResult

That way, you can test the object aside, and once you see everything working, you can be sure the problem (should you find any) is not there!!. Plus, that would make the code realy nice and short (the class definition should be inside the .h and .cpp files).

Good Luck...

Anibal.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Right Direction Please


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway