| View previous topic :: View next topic |
| Author |
Message |
seeplusplus Grandmaster Cheater
Reputation: 0
Joined: 28 Oct 2007 Posts: 562 Location: cracking accounts
|
Posted: Sun Nov 11, 2007 9:34 pm Post subject: Calc program updated Again! |
|
|
Where should I go from here? What other options to add? Any ideas welcome.
Someone wanna help me with GUI the tutorial was pretty confusing.
EDITED to hold larger numbers.
| Code: | #include <iostream>
using namespace std;
double x,y,answer;
float xf,yf,sq;
double add(double x, double y), sub(double x, double y), mult(double x, double y);
float divide(float xf, float yf),square(float sq,float squ),cube(float cu,float cub);
void options(),title();
int main (){
title();
options();
cin>>answer;
while(answer!=7){
switch(answer){
case 1:
cout<<"\nPlease enter the number to add to: ";
cin>>x;
cout<<"\nPlease enter the number to add on: ";
cin>>y;
cout<<"\nThe answer is "<<add(x,y)<<"\n\n";
options();
break;
case 2:
cout<<"\nPlease enter the number to subtract from: ";
cin>>x;
cout<<"\nPlease enter the number to subtract: ";
cin>>y;
cout<<"\nThe answer is "<<sub(x,y)<<"\n\n";
options();
break;
case 3:
cout<<"\nPlease enter the number to multiply: ";
cin>>x;
cout<<"\nPlease enter the number to multiply by: ";
cin>>y;
cout<<"\nThe answer is "<<mult(x,y)<<"\n\n";
options();
case 4:
cout<<"\nPlease enter the number to divide: ";
cin>>xf;
cout<<"\nPlease enter the number to divide by: ";
cin>>yf;
cout<<"\nThe answer is "<<divide(xf,yf)<<"\n\n";
options();
break;
case 5:
cout<<"\nPlease enter the number to square: ";
cin>>xf;
cout<<"\nPlease enter the number of times to square: ";
cin>>yf;
cout<<"\nThe answer is "<<square(xf,yf)<<"\n\n";
options();
break;
case 6:
cout<<"\nPlease enter the number to cube: ";
cin>>xf;
cout<<"\nPlease enter the number of times to cube: ";
cin>>yf;
cout<<"\nThe answer is "<<cube(xf,yf)<<"\n\n";
options();
break;
}
if(answer>6&&answer!=7){
cout<<"\nPlease enter 1,2,3,4,or 5.";
options();
}
cin>>answer;
}
return 0;
}
double add(double x, double y){
return x+y;
}
double sub(double x, double y){
return x-y;
}
double mult(double x, double y){
return x*y;
}
float divide(float xf, float yf){
return xf/yf;
}
float square(float sq,float squ){
float sqans,tempsq=0;
int k=0;
while(k<squ){sqans=tempsq+(sq*sq);tempsq=sqans+tempsq;k++;}
return sqans;
}
float cube(float cu,float cub){
float cuans,tempcu=0;
int m=0;
while(m<cub){cuans=tempcu+(cu*cu*cu);tempcu=cuans+tempcu;m++;}
return cuans;
}
void options(){
cout<<"\nPlease pick an option"<<endl;
cout<<"\n1=add, 2=sub, 3=mult, 4=div, 5=square,6=cube,7=end"<<endl;
}
void title(){
cout<<"==================================================="<<endl;
cout<<"==================================================="<<endl;
cout<<"CALCULATOR PROGRAM By: seeplusplus";
cout<<"\n==================================================="<<endl;
cout<<"==================================================="<<endl;
}
|
_________________
I am xwallflowerx...this will probably be deleted soon...
Last edited by seeplusplus on Wed Nov 14, 2007 1:16 pm; edited 2 times in total |
|
| Back to top |
|
 |
AdamWest Master Cheater
Reputation: 0
Joined: 05 Jul 2007 Posts: 354 Location: Quahog, Rhode Island
|
Posted: Sun Nov 11, 2007 9:45 pm Post subject: Re: Calc program |
|
|
revise the code, make sure the arithmetic coding is right, make a sexy GUI for it and maybe add some more functions.
_________________
"I myself am made entirely of flaws, stitched together with good intentions." - Augusten Burroughs |
|
| Back to top |
|
 |
seeplusplus Grandmaster Cheater
Reputation: 0
Joined: 28 Oct 2007 Posts: 562 Location: cracking accounts
|
Posted: Sun Nov 11, 2007 10:00 pm Post subject: Re: Calc program |
|
|
| AdamWest wrote: | | revise the code, make sure the arithmetic coding is right, make a sexy GUI for it and maybe add some more functions. |
I fail at math, but im pretty sure its working correctly, and I also have no clue how to make GUI's and what other functions should I use.
_________________
I am xwallflowerx...this will probably be deleted soon... |
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Sun Nov 11, 2007 11:08 pm Post subject: |
|
|
I think someone who names themselves after a programming language should at least know how to use it.
_________________
|
|
| Back to top |
|
 |
seeplusplus Grandmaster Cheater
Reputation: 0
Joined: 28 Oct 2007 Posts: 562 Location: cracking accounts
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Nov 12, 2007 1:55 am Post subject: |
|
|
You should go read some books and improve your code. There's a lot to do. First of all, you could make it a bit more readable, so people would actually read it.
If you wanna work with an another project, make a calc which is able to count long numbers, like 10239801839719287937357934579852323235908235 / 23847234982402384023823408230823080235802. Shouldn't be too hard.
|
|
| Back to top |
|
 |
XxOsirisxX Grandmaster Cheater Supreme
Reputation: 0
Joined: 30 Oct 2006 Posts: 1597
|
Posted: Mon Nov 12, 2007 11:43 am Post subject: |
|
|
The script is ok for learn with all those "calls" i means those add/mult/sub/div...
But it could be a lot more smaller. Also, make a GUI .
http://www.cplusplus.com/src/wintut.zip
That is a program already maked to teach how to make a window in C++.
_________________
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon Nov 12, 2007 3:41 pm Post subject: |
|
|
Do know that I am not experienced in C++, but I think you should try something like this:
| Code: |
int Main()
{
//What we want is the user to do something like:
//square 4
//or,
//add 8 2
string ToTokenize;
cin >> ToTokenize;
//Create an array out of the string--split up on the spaces
//Not sure how to do that in C++, because I just use the .Split() method in
//C#, and the setlength() in Delphi.
string[] Tokens...
//After you've done that
switch(Tokens[0].ToLower()) //The first parameter, and I'm not sure if
{ //C++ has .ToLower()
case "add":
add();
break;
case "subtract":
subtract();
break;
//Etc...
}
return 0;
}
void add()
{
//Don't know how to get an int into a string in C++, but do something like
//this (int.Parse() is C#)
int op1 = int.Parse(Tokens[1]); //operand1
int op2 = int.Parse(Tokens[2]);
cout << (op1+op2).ToString(); //ToString() is C# as well
}
|
You get where I'm going with this, don't you?
|
|
| Back to top |
|
 |
Acim Grandmaster Cheater Supreme
Reputation: 0
Joined: 04 Jun 2007 Posts: 1948 Location: If anyone has a GMS DK and they don't need it I'll have it!!
|
Posted: Mon Nov 12, 2007 3:56 pm Post subject: |
|
|
Make a GUI, which I am currently failing at.
_________________
I'm alive and well, but I quit CEF for a while. Legitly playing since Novemberish 07. Starting hacking October 06. |
|
| Back to top |
|
 |
TheSorc3r3r I post too much
Reputation: 0
Joined: 06 Sep 2006 Posts: 2404
|
Posted: Mon Nov 12, 2007 4:16 pm Post subject: |
|
|
lol samurai C++ and C# are different
_________________
Don't laugh, I'm still learning photoshop! |
|
| Back to top |
|
 |
seeplusplus Grandmaster Cheater
Reputation: 0
Joined: 28 Oct 2007 Posts: 562 Location: cracking accounts
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon Nov 12, 2007 9:55 pm Post subject: |
|
|
| seeplusplus wrote: | | XxOsirisxX wrote: | The script is ok for learn with all those "calls" i means those add/mult/sub/div...
But it could be a lot more smaller. Also, make a GUI :).
http://www.cplusplus.com/src/wintut.zip
That is a program already maked to teach how to make a window in C++. |
Thx Osiris.
@Jani, wouldn't I just change all the ints to Long?
@samurai uhh that isn't c++
I'll change it to switch case to make it shorter. |
Yeah, I know, C# != C++. However, they are similar, and the algorithm stands.
That goes for you too, Sorcerer.
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Nov 13, 2007 9:51 am Post subject: |
|
|
| seeplusplus wrote: | | @Jani, wouldn't I just change all the ints to Long? | Nope. Long isn't enough long to store infinite long numbers. Like 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840
9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840
|
|
| Back to top |
|
 |
XxOsirisxX Grandmaster Cheater Supreme
Reputation: 0
Joined: 30 Oct 2006 Posts: 1597
|
Posted: Tue Nov 13, 2007 10:06 am Post subject: |
|
|
| Jani wrote: | | seeplusplus wrote: | | @Jani, wouldn't I just change all the ints to Long? | Nope. Long isn't enough long to store infinite long numbers. Like 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840
9238402840239840238940238408230482340820840239840298940823098498230948230482304982308402384028034823049238402840239840238940238408230482340820840 |
That why ppl put a limit. Also, there are no reason to wants a number that high, else you attemp to crash the program.
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Nov 13, 2007 12:26 pm Post subject: |
|
|
| XxOsirisxX wrote: | | That why ppl put a limit. Also, there are no reason to wants a number that high, else you attemp to crash the program. | Exactly! They limit you! Where's your freedom? It's like you couldn't buy more than 5 different stuff from your local shop.. What's the point?
Oh yeh, btw.. Do you think that no one needs long numbers either then? What's the point of having long numbers, if you can't do anything with them? What if you need accurate numbers for something really important calculation, (I can't think up you doing anything important, tho ;D) and then mess it up, because you calculated the sum with rounded numbers? zomg, like 1000 ppl died because of your rounding, GG.
PS. He wanted practise, there's some pratise for him. What's the point of reinventing the wheel, if not practising? Someone has already done it and you could leech him/her off, but you wouldn't learn anything else than leeching.
PPS. Getting a bit offtopic, but whatever.
|
|
| Back to top |
|
 |
|