+ 1
Can someone tell me why this isn't working or help me correct it?
This is the start of a c++ project I'm working on, but I keep getting errors that I don't know how to patch. Help is desperately needed. int a, b; string name ; cin >> a; cin >> name; cin >> b; int sum = a + b; int difference1 = a - b; int difference2 = b - a; int product = a * b; int quotient1 = a / b; int quotient2 = b / a; if (!stricmp(name.c_str(), "plus")){ cout << "sum" << endl ; }
6 Answers
+ 3
it's strcmp() not stricmp() and on sololearn it is in the cstring header
#include <cstring>
also if either a or b are 0 you'll receive an error.
+ 3
Xan Oh ya, forgot about that one. Guess that's why C++ isn't my primary lang. lol So, maybe just needed the correct header then? Cause, the code works for me with strcmp() and <cstring> on SL, but I haven't tried the other typical headers that include strcmp(), stricmp().
+ 2
Yes, header problem, you were spot on with that. Also they were printing "sum" (the string) rather than sum (the variable).
+ 1
ChaoticDawg No. stricmp() is correct, the i stands for insensitive, as in case-insensitive.
0
What is the if statement saying, I havenât come across strcmp before. lol just trying to learn as much as I can, Thanks