hello this is my first C++ program
my problem is that i cant find out to things
frist is that when i rune it and sett the mathe type it is ignored laiter and hit shows alle offe the posbole mathe types ( that i have enterd +,-,/ and * )

secone prolem is that if i try to multiply or divid whitt 0 my system crashes,
i see that it is a math problem for the pc or somthing butt i have no idd how to fix it.

i was thing som sorrt of program that maksi it so IF num1 or num2 and it is divid or multyply it will render awnser 0 and dont crash it ....

(sorry about my bade writing i am dislectic)

hoppe any one can help

#include <iostream>
#include <conio.h>
#include <string>
using namespace std;


int addition(int x, int y);

int substract(int x, int y);

int multiply(int x, int y);

int divid(int x, int y);

void main(){
	int num1;
	int num2;
	string a;
	cout << "what type of math do you want to do?";
		cout << endl;
		cout << "addition(+), substract(-), multiply(*) or divid(/)" <<endl;
		getline(cin, a);
		cin.clear();
		cout << "you want to " << a <<endl;
		cout << "the first number:  ";
		cin >> num1;
		cout << " the secon number: ";
		cin >> num2;

		bool(a == "add" || "+");
		"{";true; 
			; cout << "the awnser is"; 
		cout <<addition(num1, num2); 
		cout << endl;
		false; {
			cout << "";
		};
		 "}";
		 

		bool(a == "substract" || "-"); 
		if (true)	"{" 
		; cout << "the awnser is";
		 cout << substract(num1,num2);
		 cout << endl;
		"}";
		if (false) "{" 
			; cout << "";
		 "}";
		

		bool(a == "multply" || "*" );
			"{" ;true ;{
		; cout << "the awnser is";
		cout << multiply(num1, num2);
		cout << endl; };
		false; {
			cout << "";
		};
		"}";



		bool(a == "divid" || "/"); 
			"{";true; 
		; cout << "the awnser is";
cout << divid(num1, num2);	
cout << endl;
			false; {
				cout << "";
			};
		"}";



		_getch();

}

int addition (int x, int y) {
	int numawnser;
numawnser = x + y;
return numawnser;
}


int substract (int x, int y) {
	int numawnser;
numawnser = x - y;
return numawnser;
}

int multiply (int x, int y) {
	int numawnser;
numawnser = x * y;
return numawnser;
}

int divid (int x, int y) {
	int numawnser;
numawnser = x / y;
return numawnser;
}

The format of your if() statements is completely wrong.
The structure is:

if( condtion == value )
{
	//actions		
}

So for your Addition check you want something like this.

if( a == "add" || a == "+" )
{
	cout << "the answer is ";
	cout << addition(num1, num2) << endl;
}
else if( a == "subtract" || a == "-" )
{
	//and so on	
}

Things to notice are that you cannot just put if(a == "add" || "+") because "+" will always be true therefore it should always run (test it out).
Also using an elseif() statement for makes it so if you are doing addition then you do not have to check the subtraction/multiplication/division if() statements.

For your division check just put in an if() statement that checks to see if num2 is equal to 0 and if it is then output "Cannot divide by zero!" or something and otherwise output the answer. I am 100% sure that you can multiply by 0 so I think it was just calling your division function even though I'm not sure how that code even ran.

first change the string to char.

void main(){
	int num1;
	int num2;
	//string a;
        char a;

then change the cher to int with using atoi()

int a_a = atoi(a); //return the INT value of the charter

and then use simple switch.

switch(a_a){
      case '+':
      {
      // action()
      break;
      }
}

hope its help.

by the way you have to learn the original c++. if you need any help in the feature. contact me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.