Can someone tell me why this isn't working or help me correct it? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 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 ; }

27th Apr 2018, 1:38 AM
JDLives
6 Respuestas
+ 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.
27th Apr 2018, 1:56 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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().
27th Apr 2018, 2:55 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Yes, header problem, you were spot on with that. Also they were printing "sum" (the string) rather than sum (the variable).
27th Apr 2018, 2:57 AM
Emma
+ 1
ChaoticDawg No. stricmp() is correct, the i stands for insensitive, as in case-insensitive.
27th Apr 2018, 2:51 AM
Emma
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
1st May 2018, 1:05 AM
Val
Val  - avatar