+ 1

Can't find out why

#include <iostream> #include <deque> #include <ctime> #include <cstdlib> bool isWork(){ bool isWork = false; int randdom = rand()%2; return(rand == 0?isWork = false:isWork = true); } int FriendsOfMine(std::deque<std::string> friends, int amount){ bool isTrue = isWork; std::cout << amount;//it doesn't outputs //anything std::string ally, howard, john, thom; if(isTrue){ amount == 0?ally = "works":amount == 1?howard = "works":amount == 2?john = "works":amount == 3?thom = "works":thom = " "; return amount; } return(friends, amount += 1); } int main() { srand(time(NULL)); std::deque<std::string> b; std::string alice, bob; b[0] = alice; b[1] = bob; FriendsOfMine(b, 0);//here i called this //function return 0; } I will appreciate your help😗

5th Sep 2018, 4:22 AM
Oleg Storm
Oleg Storm - avatar
1 Answer
+ 9
In main(), alice and bob are string variables, not string literals. I'm quite sure that's the wrong method to add elements to deque as well. isWork is local to function isWork() and is not accessible by FriendsOfMine(). At this point, it assigns the function pointer to the boolean variable in FriendsOfMine(), which isn't what you want. (Perhaps you wanted to call isWork() ?) Some ternary statements do not appear to work correctly, or at least can be significantly simplified.
5th Sep 2018, 4:27 AM
Hatsy Rei
Hatsy Rei - avatar