[SalesForce] Trigger to update opportunity stage based on Account Status

I have a trigger that updates/ inserts opportunities when the account is created. This was implemented by a third party. Now I would like to update the opportunities to Cancelled when the Account status= 'Cancelled'.

I have tried this via workflow rules and field update but this did not work.
Below is my attempt to create the trigger, but I think its terribly wrong. Help would be greatly appreciated.

trigger updateopporutnites on Account (after update) {

Set<String> Account=new Set<String>();
for(Account ac : Trigger.new)
{
if(ac.Status__c=='Cancelled')
Account.add(ac.OpportunityId);
}
for(Opportunity opp : [select id, StageName from Opportunity where id in: Account])
{
opp.StageName='Closed - Cancelled';
update opp;
}
}

Best Answer

You're very, very close. What you need to do is gather up the Account Ids and query for the Opportunities using them since each Account could have multiple Opportunities.

You also need to remove your DML from the loop to bulkify your trigger.

 trigger updateopportunities on Account(after update) 
{
    Set<Id> accountIds = new Set<Id>();

    for(Account ac : Trigger.new)
    {
         if(ac.Status__c=='Cancelled')
              accounIds.add(ac.Id);
    }

     List<Opportunity> oppsToUpdate = new List<Opportunity>();

     for(Opportunity opp : [select id, StageName from Opportunity where AccountId in: accountIds])
     {
          opp.StageName='Closed - Cancelled';
          oppsToUpdate.add(opp);
     }

     update oppsToUpdate;
}