Hey everyone, I hope I have this in the right forum.. I'm using Microsoft Visual C++ 6.0.. I'm just starting to learn to program, and I was trying to make an extremely basic calculator.
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
int Add(int x, int y)
{
return(x+y);
}
int main()
{
char text[512];
int num1;
int num2;
int num3;
while(1)
{
cout << "Menu" << endl;
cout << endl <<"Add" << endl;
cout << "Subtract" << endl;
cout << "Multiply" << endl;
cout << "Divide" << endl;
cout << endl << "What would you like to do? ";
cin.getline(text, 512);
if (strcmpi(text, "add") == 0) {
cout << "Enter two numbers to add:" << endl;
cin >> num1;
cin >> num2;
num3 = Add(num1, num2);
cout << num3 << endl;
}
else
{
cout << "Unknown command." << endl;
}
}
}
That's my code.. My problem is, right when I type in add and it does everything inside of the if statement, it still goes down and does what's in the else statement.. So it will add two numbers together and then still say "Unknown command.". Does anyone have an idea of what might be going on? Thanks.
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
int Add(int x, int y)
{
return(x+y);
}
int main()
{
char text[512];
int num1;
int num2;
int num3;
while(1)
{
cout << "Menu" << endl;
cout << endl <<"Add" << endl;
cout << "Subtract" << endl;
cout << "Multiply" << endl;
cout << "Divide" << endl;
cout << endl << "What would you like to do? ";
cin.getline(text, 512);
if (strcmpi(text, "add") == 0) {
cout << "Enter two numbers to add:" << endl;
cin >> num1;
cin >> num2;
num3 = Add(num1, num2);
cout << num3 << endl;
}
else
{
cout << "Unknown command." << endl;
}
}
}
That's my code.. My problem is, right when I type in add and it does everything inside of the if statement, it still goes down and does what's in the else statement.. So it will add two numbers together and then still say "Unknown command.". Does anyone have an idea of what might be going on? Thanks.