 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Negima I post too much
Reputation: 6
Joined: 22 May 2007 Posts: 2221
|
Posted: Thu Apr 10, 2008 9:49 pm Post subject: Problem with calculator |
|
|
I expected this to keep looping the variable functionNum to 0 and I could just keep doing a different math function, but when I do 1 function I cant do another.
| Code: | //NegiCalculator
//Made by negima of CEF
#include <iostream>
int main()
{
int functionNum, x, y;
std::cout << "Hello, and welcome to NegiCalculator\n";
std::cout << "I can do 4 main mathmatical functions\n";
std::cout << "These functions are...\n";
std::cout << "1. Add\n";
std::cout << "2. Subtract\n";
std::cout << "3. Multiply\n";
std::cout << "4. Divide\n";
std::cout << "Please type one of the function numbers (1-4) to begin\n";
std::cin >> functionNum;
if (functionNum == 2)
{
std::cout << "Please enter a number\n";
std::cin >> x;
std::cout << "Please enter another number to subtract from your first number\n";
std::cin >> y;
std::cout << x << " subtracted by " << y << " equals " << x-y << "\n";
std::cout << "What would you like to do next?\n";
std::cout << "1. Add\n";
std::cout << "2. Subtract\n";
std::cout << "3. Multiply\n";
std::cout << "4. Divide\n";
functionNum = 0;
std::cin >> functionNum;
}
if (functionNum == 3)
{
std::cout << "Please enter two numbers to multiply\n";
std::cin >> x;
std::cin >> y;
std::cout << x << " Multiplyed by "<< y << " equals " << x*y << "\n";
std::cout << "What would you like to do next?\n";
std::cout << "1. Add\n";
std::cout << "2. Subtract\n";
std::cout << "3. Multiply\n";
std::cout << "4. Divide\n";
functionNum = 0;
std::cin >> functionNum;
}
if (functionNum == 4)
{
std::cout << "Please enter a number, then another number to divide it by\n";
std::cin >> x;
std::cin >> y;
std::cout << x << " Divided by " << y << " equals " << x/y <<"\n";
std::cout << "What would you like to do next?\n";
std::cout << "1. Add\n";
std::cout << "2. Subtract\n";
std::cout << "3. Multiply\n";
std::cout << "4. Divide\n";
functionNum = 0;
std::cin >> functionNum;
}
{
if (functionNum == 1)
std::cout << "Please enter two numbers to add\n";
std::cin >> x;
std::cin >> y;
std::cout << "The sum of " << x << " and " << y << " equals " << x+y << "\n";
std::cout << "What would you like to do next?\n";
std::cout << "1. Add\n";
std::cout << "2. Subtract\n";
std::cout << "3. Multiply\n";
std::cout << "4. Divide\n";
functionNum = 0;
std::cin >> functionNum;
}
}
|
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Apr 10, 2008 10:15 pm Post subject: |
|
|
Because there's no loop.
e: oh man. that was a wtf moment.
| Code: | //SloviCalculator
//Made by slogima of CEF
#include <iostream>
int x, y, op;
void choices(){
std::cout << "Hello, and welcome to NegiCalculator\n";
std::cout << "I can do 4 main mathmatical functions\n";
std::cout << "These functions are...\n";
std::cout << "1. Add\n";
std::cout << "2. Subtract\n";
std::cout << "3. Multiply\n";
std::cout << "4. Divide\n";
std::cout << "5. Exit\n";
std::cout << "Please type one of the function numbers (1-4) to begin\n";
std::cin >> op;
}
void add(){
std::cin >> x;
std::cin >> y;
std::cout << x+y << std::endl;
}
void sub(){
std::cin >> x;
std::cin >> y;
std::cout << x-y << std::endl;
}
void mul(){
std::cin >> x;
std::cin >> y;
std::cout << x*y << std::endl;
}
void divCOMPILERSGONNABITCH(){
std::cin >> x;
std::cin >> y;
if(y != 0){
std::cout << x/y << std::endl;
}
else{
std::cout << "Try not dividing by zero next time.";
}
}
int main()
{
do{
choices();
switch(op)
{
case 1:
add();
break;
case 2:
sub();
break;
case 3:
mul();
break;
case 4:
divCOMPILERSGONNABITCH();
break;
default:
std::cout << "What?\n\n";
break;
}
}while(op != 5);
} |
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Apr 10, 2008 10:28 pm Post subject: |
|
|
There are a couple of things wrong with your code. First off, you don't need to assign 0 to functionNum. Second off the name functionNum is confusing considering you don't actually have any functions (=P). So I suggest you make an add, sub, mult, and div function. Anyway, the reason you can't do another is because you pass the value to functionNum, but then thats it. You don't check for anything. Here's how I would do this.
| Code: |
//NegiCalculator
//Made by negima of CEF
#include <iostream>
void add();
void sub();
void mult();
void div();
void drawmenu();
int main()
{
int functionNum, x, y, choice;
drawmenu();
return 0;
}
void drawmenu()
{
std::cout << "Hello, and welcome to NegiCalculator\n";
std::cout << "I can do 4 main mathmatical functions\n";
std::cout << "These functions are...\n";
std::cout << "1. Add\n";
std::cout << "2. Subtract\n";
std::cout << "3. Multiply\n";
std::cout << "4. Divide\n";
std::cout << "Please type one of the function numbers (1-4) to begin\n";
std::cin >> functionNum;
switch(functionNum) {
case 1:
add();
break;
case 2:
sub();
break;
case 3:
mult();
case 4:
div();
default:
cout<<"Invalid option. Seeing as you are too stupid as to read and comply, you don't deserve to use this program. Goodbye.\n";
return(1);
}
}
void add()
{
std::cout << "Please enter two numbers to add\n";
std::cin >> x;
std::cin >> y;
std::cout << "The sum of " << x << " and " << y << " equals " << x+y << "\n";
cout<<"Go back to menu? (1 for yes, 2 for no)\n";
cin>>choice;
if(choice == 1) {
drawmenu()
}
else {
return 0;
}
}
void sub()
{
std::cout << "Please enter a number\n";
std::cin >> x;
std::cout << "Please enter another number to subtract from your first number\n";
std::cin >> y;
std::cout << x << " subtracted by " << y << " equals " << x-y << "\n";
cout<<"Go back to menu? (1 for yes, 2 for no)\n";
cin>>choice;
if(choice == 1) {
drawmenu()
}
else {
return 0;
}
}
void mult()
{
std::cout << "Please enter two numbers to multiply\n";
std::cin >> x;
std::cin >> y;
std::cout << x << " Multiplyed by "<< y << " equals " << x*y << "\n";
cout<<"Go back to menu? (1 for yes, 2 for no)\n";
cin>>choice;
if(choice == 1) {
drawmenu()
}
else {
return 0;
}
}
void div()
{
if (functionNum == 4)
{
std::cout << "Please enter a number, then another number to divide it by\n";
std::cin >> x;
std::cin >> y;
std::cout << x << " Divided by " << y << " equals " << x/y <<"\n";
cout<<"Go back to menu? (1 for yes, 2 for no)\n";
cin>>choice;
if(choice == 1) {
drawmenu()
}
else {
return 0;
}
}
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|