program not working propaly.help!

#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>//is this neccesory
int main()
{
int add,sub,answer,done;
labelA:
cout<<"whats is the basic mathamatical operation you want to perform? \n";
cout<<"please answer with add-for addition sub-for subtraction.\n";//program prints this then become unresponsive.when the applications "close on exit" is unchecked from the properties.when it checked closes automatically.
cin<<answer;
if (answer==add)
{
//program of addition
long double value1;
long double value2;
long double output1;

cout<<"Enter first number for addition. \n";
cin>>value1;
cout<<"Enter second number for addtion. \n";
cin>>value2;
output1=value1+value2;
cout<<"The sum of these two number: "<<output1;

goto labelA;

}
if (answer==sub)
{
//program of subtraction
long double sub1;
long double sub2;
long double ans2;

cout<<"Enter the first number for subtraction.\n";
cin>>sub1;
cout<<"Enter the second number for subtraction.\n";
cin>>sub2;
ans2=sub1-sub2;
cout<<"The sub of these two numbers are: "<< ans2;
goto labelA;
}
if (answer==done)
{cout<<"thank you for using this program.Good bye" <<endl;
getch();
}
return 0;
}
//any solutions will be greatly appreciated.
Can you at least explain what the heck your program does and what the error is?
First of all this statement is incorrect

cin<<answer;

Shall be

cin>>answer;

And according to the logic of your program variable answer shall have type std::string instead of int.
Last edited on
compiling does not shows any errors.but when i run the program.after the first two couts shows.when i input my answer to the application' its closes automatically.
I think your issue is the fact that you are checking whether the input is equal to an undefined variable

What you should do is:

1
2
3
4
5
6
if (answer == "add"){
    <execute code here>
}
if (answer == "sub"){
    <execute code here>
}


Hope this helps!

EDIT: And also, try not to use the goto statement
Last edited on
yeah.many people says that.i know that i have to add loop in in the program.but i dont know.please edit the code and add loop.that would be a great help
Why can't you edit it yourself?
Topic archived. No new replies allowed.