Hello ppl!
I'm write a simple arithmetic program using functions. The program should SUM two numbers, before that the if statement have to evaluate if this entered simbols is INT (TRUE) or CHAR (FALSE). After that program calculate this two numbers.
My source:
#include <iostream>
int suma(int a, int b);
/* function should test is it true number or char */
int itest(int x, int y)
{
char w, z;
if ((x != w) || (y != z)) /* here int should not to be equal to char (somehow) */
return x, y;
else
{
std::cout << "Please enter only a number not char!\n";
/* here have to be a expression to start again */
}
}
int main()
{
std::cout << "Hello, here a funcion will sum your numbers! \n";
std::cout << "Please enter two integers: \n";
int a, b, c;
std::cin >> a;
std::cin >> b;
itest(a, b);
c = suma(a, b);
std::cout << "\nThe sum is: \t" << c;
return 0;
}
/* SUM of a, b */
int suma(int x, int y)
{
std::cout << "\nWe got number " << x << " and " << y;
1) You cannot return 2 numbers from a function, return x,y; is invalid
2) If someone enters a char for your cin statement, then it's converted to an int when it's stored in a or b. So you cannot then check if they entered a char or not.
3) you cannot go char x, if (x != w) because this checks the values of the objects, not the type.