house in those two cities wont be available for purchase till you help 3 citizens in each of those cities and become thane. speak to Stuarts or Jars to see what quests you have to do i order to become thane in those two cities
Nope, you must own the houses first before the Jarls will offer you the title of Thane, and doing favors for citizens (5, not 3, to be exact) is also a requirement for becoming Thane but not for buying the house in Markarth. In Riften the Jarl will not offer you the house unless you have already done the favor quests, but you must still buy the house as a prerequisite to becoming Thane.
For Markarth, if Igmund is still Jarl you need to do a favor quest for him which typically involves retrieving a family heirloom from a Forsworn camp (and IIRC killing the Forsworn leader there. You must be level 20 or above before he will offer you the quest.
If you are doing the Civil War for the Stormcloaks and this has resulted in Throngvar Silver-Blood becoming Jarl instead, he may offer you the option to buy the Markarth house as a reward for your military service instead of requiring you to complete a favor quest. At least this is what happened to me on my last two SC characters. I don't know if it requires that the war be finished, or if having given Markarth to the SCs in the ceasefire negotations instead of taking it militarily makes a difference.
In Riften you must complete three quests for the Jarl involving the local Skooma trade (and, as noted above, do the five favors for citizens that also get you the Thane title) before she will offer you the house there. The first of the three quests is no big deal but AFAIK it's the only way to progress to the next one.
See here for details on the house in Markarth: http://www.uesp.net/wiki/Skyrim:Vlindrel_Hall
and here for details on the one in Riften: http://www.uesp.net/wiki/Skyrim:Honeyside
Markarth is especially tricky, if I remember right. One quest requires you to be locked up and escape from Skyrim's version of Alcatraz.
There is such a quest in Markarth but it doesn't have anything to do with buying a house there, other than the fact that completing it can sometimes bug out your dialogue with the Jarl there making it impossible to get the quest that actually does lead to buying the house.